ウィンドウオブジェクトのプロパティとメソッド
Window オブジェクトのプロパティ
まず、Window オブジェクトのすべてのプロパティがループを通過します:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> //循環(huán)遍歷window對象的所有屬性 /* for(name|index in obj|arr){ } 描述:只能循環(huán)數(shù)組的下標,或?qū)ο蟮膶傩浴? 說明:如果循環(huán)數(shù)組的話,每次循將取下標值。 對于數(shù)組中值為undefined的,不會循環(huán)。 循環(huán)數(shù)組,只返回有效的值。 如果循對象的話,每次循環(huán)取對象屬性。 嚴格的來說,對象中沒有方法一說,所有的都是屬性。 將一個函數(shù)賦給一個屬性后,這個屬性就變成方法了。 */ var i = 1; for(var name in window) { document.write(i+" "+name+"<br>"); i++; } </script> </head> <body> </body> </html>
name: ブラウザ ウィンドウの名前またはフレームの名前を指します。この名前は、a タグの target 屬性に使用されます。
ウィンドウの名前を設定します: window.name = "newWin"
ウィンドウの名前を取得します: document.write(name);
top: トップを表します-レベルウィンドウ。例: window.top
parent: 親ウィンドウを表し、主にフレームに使用されます。
self: 現(xiàn)在のウィンドウを表し、主にフレームで使用されます。
innerWidth: ブラウザウィンドウの內(nèi)側(cè)の幅を指します (メニューバー、ツールバー、アドレスバー、ステータスバーを除く)。この屬性は Firefox でサポートされています。
IE では、window.innerWidth の代わりに document.documentElement.clientWidth を使用します
innerHeight: ブラウザ ウィンドウの內(nèi)側(cè)の高さを指します (メニュー バー、ツールバー、アドレス バー、ステータス バーを除く)。 、このプロパティは Firefox でサポートされています。
- IE では、window.innerHeight の代わりに document.documentElement.clientHeight を使用します
- document.documentElement は <html> マーク オブジェクトです
- document.body は <body >Mark オブジェクトです
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> //實例:測試當前網(wǎng)頁的寬度和高度 //兼容所有瀏覽器 var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth; var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight; //輸出結(jié)果 document.write("寬度:"+width+",高度:"+height); </script> </head> <body> </body> </html>
window オブジェクト メソッド
- alert(): 警告ダイアログ ボックスをポップアップ表示します。
- prompt(): 入力ダイアログボックスをポップアップ表示します。
- confirm(): 確認ダイアログボックスをポップアップ表示します。 [OK] ボタンがクリックされた場合は true を返し、[キャンセル] をクリックされた場合は false を返します。
- close(): ウィンドウを閉じる
- print(): ウィンドウを印刷する
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>php.cn</title> <script> function delect() { if(window.confirm("你確認要刪除嗎?")){ //跳轉(zhuǎn)到指定刪除頁面執(zhí)行刪除操作 location.href="http://ipnx.cn"; } } </script> </head> <body> <a href="#" onClick="delect()">刪除</a> </body> </html>