標籤:
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 = ‘父視窗變數‘;//測試setTimeoutfunction sayHello(){alert(‘hello!‘);//return function(){alert(‘hello!‘)};}function testTimeout(){window.setTimeout(sayHello, 2000);//window.setTimeout(sayHello(), 2000);}//測試setIntervalvar 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 = ‘基本上為主‘;}
1.BOM學習