<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Document</title> <script type="text/javascript"> window.onload = function(){ var oInput = document.getElementById('input1'); var oIframe = document.getElementById('iframe1'); oInput.onclick = function(){ //oIframe.contentWindow.document.getElementById('div1').style.color = 'red';//所有浏览器都支持 oIframe.contentDocument.getElementById('div1').style.color = 'red';//ie6 7不支持 } /*其他的一些操作: window.parent:表示父层的window window.top:表示最顶层的window 注意iframe的onload事件在ie下只能用绑定的形式,attachEvent('onload',function(){}); 防钓鱼: if(window!=window.top){ window.top.location.href = window.location.href; }*/ } </script> </head> <body> <input type="button" value="改变" id="input1" /> <iframe src="iframe1.html" id="iframe1"></iframe> </body> </html>