Window innerWidth 屬性

定義和用法

innerWidth 屬性返回窗口內容區域的寬度。

innerWidth 屬性是只讀的。

另請參閱:

innerHeight 屬性

outerWith 屬性

outerHeight 屬性

實例

例子 1

獲取窗口寬度:

let width = window.innerWidth;

親自試一試

let width = innerWidth;

親自試一試

例子 2

所有高度和寬度屬性:

let text =
"<p>innerWidth: " + window.innerWidth + "</p>" +
"<p>innerHeight: " + window.innerHeight + "</p>" +
"<p>outerWidth: " + window.outerWidth + "</p>" +
"<p>outerHeight: " + window.outerHeight + "</p>";

親自試一試

語法

window.innerWidth

或者:

innerWidth

返回值

類型 描述
數字 瀏覽器窗口內容區域的內部寬度(以像素計)。

瀏覽器支持

所有瀏覽器都支持 window.innerWidth

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
支持 9-11 支持 支持 支持 支持