windows:
屬性:opener。
代表父窗體:window.opener.test(); ---調用父窗體中的test()方法。
<input type="button" value="打開我的窗口" onclick="openWin()" /> function openWin(){ myWindow=window.open('','','width=200,height=100'); myWindow.document.write("<p>這是我的窗口</p>"); myWindow.focus(); myWindow.opener.document.write("<p>這個是源窗口!</p>"); }
方法:
打開/關閉窗口:
open():
window.open([URL], [窗口名稱], [參數字符串]) <script type="text/javascript"> window.open('https://www.baidu.com','_blank','width=300,height=200,scrollbars=yes')
close():
window.close(); //關閉本窗口
關閉新建的窗口。 <script type="text/javascript"> var mywin=window.open('https://www.baidu.com'); //將新打的窗口對象,存儲在變量mywin中 mywin.close();
定時器:
setTimeout():時間到了, 就會執行一個指定的 method/function
setTimeout("changeState()",1000 ); function changeState(){ alert("這是等待三秒"); }
setInterval():setInterval() 方法可按照指定的周期(以毫秒計)來調用函數或計算表達式。
var biao = 0; setInterval("changeState()",1000 ); function changeState(){ biao++; alert(biao); }
清除定時器:
var timer1=window.setTimeout(function(){},1000); //timer1->1 當前是第一個定時器 var timer2=window.setTimeout(function(){},1000); //timer2->2 當前是第二個定時器 window.clearTimeout(timer1);window.clearInte
scrollTo():scrollTo() 方法可把內容滾動到指定的坐標。
<input type="button" value="移動滾動條" onclick="scrollWindow()" /> function scrollWindow(){ window.scrollTo(100,500); }
moveTo():將窗口移動到某一位置
<body> <input type="button" value="打開窗口" onclick="openWin()" /> <br> <input type="button" value="移動窗口" onclick="moveWin()" /> </body> function openWin(){ myWindow=window.open('','','width=200,height=100'); myWindow.document.write("<p>這是我的窗口</p>"); } function moveWin(){ myWindow.moveTo(100,0); myWindow.focus();//將輸入焦點定位在myWindow
location:
屬性:href
用腳本來跳轉頁面。
window.location.href = "https://www.baidu.com";
方法:reload()。
刷新頁面。
window.location.reload();
history:
方法:go()
history.go(num)表示向前或向后翻多少頁,num為正數表示向前翻,為負數則向后翻。