Latest web development tutorials

Window innerWidth 和innerHeight 屬性

Window 對象參考手冊 Window對象

定義和用法

innerheight 返回窗口的文檔顯示區的高度。

innerwidth 返回窗口的文檔顯示區的寬度。

注意:使用outerWidth和outerHeight屬性獲取加上工具條與滾動條窗口的寬度與高度。


語法

Get:

window.innerWidth
window.innerHeight

設置:

window.innerWidth=pixels
window.innerHeight=pixels


瀏覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主流瀏覽器都支持innerWidth 和innerHeight 屬性。

注意:IE 8 及更早IE版本不支持這兩個屬性。


實例

實例

獲取窗口的高度與寬度(不包含工具條與滾動條):

var w=window.innerWidth;
var h=window.innerHeight;

嘗試一下»


Window 對象參考手冊 Window對象