标签:
1.bom.html
<html> <head> <title>bom演示</title> <script type="text/javascript" src="js/bom.js"></script> </head> <body> <div id = ‘d1‘>第一个div</div> <div id = ‘d2‘>第二个div</div> <a href="javascript:test();">测试</a></br> <a href="javascript:testTimeout();">测试setTimeout</a></br> <a href="javascript:testSetInterval();">测试setInterval</a></br> <a href="javascript:stopInterval();">停止Interval</a></br> <a href="javascript:alert(document.links.length);">多少个link?</a></br> <a href="javascript:alert(document.links[0]);">第一个link的地址</a></br> <a href="javascript:changeHtml();">改变第一个div的内容为“基本上为主”</a></br> </body> </html>
2.child.html
<html> <head> <title>子窗口</title> <script type="text/javascript" src="js/bom.js"></script> </head> <body> <a href="javascript:alert(window.opener.msg);">子窗口访问父窗口的变量</a> </body> </html>
3.bom.js
//alert(window); //alert(window.document); //alert(window.document.links); //alert(window.document.anchors); //alert(window.document.forms); //alert(window.document.location); function test(){ //恶搞 /* while(1 > 0){ window.moveTo(Math.random()*1000, Math.random()*100); //window.moveBy(400, 600); } */ //alert(window.screenX); //alert(window.self); //window.open(‘child.html‘, ‘topFrame‘); var kti = 99888; alert(window.kti); } window.msg = ‘父窗口变量‘; //测试setTimeout function sayHello(){ alert(‘hello!‘); //return function(){alert(‘hello!‘)}; } function testTimeout(){ window.setTimeout(sayHello, 2000); //window.setTimeout(sayHello(), 2000); } //测试setInterval var t; function testSetInterval(){ t = window.setInterval(sayHello, 1000); } function stopInterval(){ window.clearInterval(t); } //改变html内容 function changeHtml(){ var k = document.getElementById(‘d1‘); alert(k); k.innerHTML = ‘基本上为主‘; }
标签:
原文地址:http://www.cnblogs.com/shamgod/p/4641131.html