亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript Window - 瀏覽器物件模型

瀏覽器物件模型 (BOM)

瀏覽器物件模型(Browser?Object?Model (BOM))尚未正式標準。

由於現(xiàn)代瀏覽器已經(jīng)(幾乎)實作了 JavaScript 互動性方面的相同方法和屬性,因此常被認為是 BOM 的方法和屬性。

window 物件

瀏覽器開啟一個文檔,就建立了一個 window 對象,即 window 物件表示瀏覽器中開啟的視窗。

window 物件是全域?qū)ο?,可以把視窗的屬性當作全域變?shù)來使用。例如,可以只寫 document,不必寫 window.document。同樣,可以把目前視窗物件的方法當作函數(shù)來使用,如只寫 alert(),而不必寫 Window.alert()。

如果文件包含框架(frame),瀏覽器會為文件建立一個 window 對象,並為每個框架建立一個額外的 window 物件。

提示:window 物件雖然沒有明確的相關(guān)標準,但所有瀏覽器都支援該物件。

HTML DOM 的document 也是window 物件的屬性之一:

window.document.getElementById("header");

#與此相同:

document.getElementById("header");


Window 尺寸

有三種方法能夠確定瀏覽器視窗的尺寸(瀏覽器的視口,不包括工具列和捲軸)。

對於Internet Explorer、Chrome、Firefox、Opera 以及Safari:

window.innerHeight - 瀏覽器視窗的內(nèi)部高度

window.innerWidth - 瀏覽器視窗的內(nèi)部寬度

對於Internet Explorer 8、7、6、5:

document.documentElement.clientHeight

document.documentElement.clientWidth

document.body.clientHeight

document.body.clientWidth

實用的JavaScript 方案(涵蓋所有瀏覽器):

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文網(wǎng)(php.cn)</title>
</head>
<body>
<p id="demo"></p>
<script>
var w=window.innerWidth
|| document.documentElement.clientWidth
|| document.body.clientWidth;
var h=window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;
x=document.getElementById("demo");
x.innerHTML="瀏覽器window寬度: " + w + ", 高度: " + h + "。"
</script>
</body>
</html>

其他Window 方法

一些其他方法:

window.open() - 開啟新視窗

window.close() - 關(guān)閉目前視窗

window.moveTo() - 移動目前視窗

window.resizeTo() - 調(diào)整目前視窗的尺寸


繼續(xù)學習
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script type="text/javascript"> myWindow=window.open('','','width=200,height=100') myWindow.document.write("This is 'myWindow'") myWindow.moveTo(0,0) </script> </head> <body> <p>把新窗口移動到指定屏幕左上角(屏幕左上角為 0,0 坐標,往右和下計算為正)</p> </body> </html>