--- title: Window.innerHeight slug: Web/API/Window/innerHeight translation_of: Web/API/Window/innerHeight --- <div>{{APIRef}}</div> <h2 id="Summary" name="Summary">概述</h2> <p>浏览器窗口的视口(viewport)高度(以像素为单位);如果有水平滚动条,也包括滚动条高度。</p> <div class="note"><strong>Note:</strong> If you use {{ifmethod("nsIDOMWindowUtils", "setCSSViewport")}} to set the virtual window size for page layout purposes, the value returned by this property corresponds to the viewport height set using that method.</div> <h2 id="Syntax" name="Syntax">语法</h2> <pre class="syntaxbox">var <var>intViewportHeight</var> = window.innerHeight;</pre> <h3 id="Value" name="Value">值</h3> <p><code>intViewportHeight</code> 为浏览器窗口的视口的高度。</p> <p><code>window.innerHeight</code> 属性为只读,且没有默认值。</p> <h2 id="Notes" name="Notes">备注</h2> <p>任何窗口对象,如<font face="Courier New, Andale Mono, monospace"> </font>{{domxref("window")}}、frame、frameset 或 secondary window 都支持 <code>innerHeight</code> 属性。</p> <p>有一个<a class="link-https" href="https://bugzilla.mozilla.org/show_bug.cgi?id=189112#c7" title="https://bugzilla.mozilla.org/show_bug.cgi?id=189112#c7">算法</a>用来获取不包括水平滚动条的视口高度。</p> <h2 id="Example" name="Example">例子</h2> <h3 id="假设有一个_frameset">假设有一个 frameset</h3> <pre class="brush:js">var intFrameHeight = window.innerHeight; // or var intFrameHeight = self.innerHeight; // 返回frameset里面的frame视口的高度 var intFramesetHeight = parent.innerHeight; // 返回上一级frameset的视口的高度 var intOuterFramesetHeight = top.innerHeight; // 返回最外部frameset的视口的高度 </pre> <p>{{todo("link to an interactive demo here")}}</p> <p>改变一个窗口的大小,可以查看 {{domxref("window.resizeBy()")}} 和 {{domxref("window.resizeTo()")}}。</p> <p>想获取窗口的外层高度(outer height),即整个浏览器窗口的高度,请查看 {{domxref("window.outerHeight")}}。</p> <h3 id="Graphical_example" name="Graphical_example">图像示例</h3> <p>下面的示意图展示了 <code>outerHeight</code> 和 <code>innerHeight</code> 两者的区别。</p> <p><img alt="innerHeight vs outerHeight illustration" src="/@api/deki/files/213/=FirefoxInnerVsOuterHeight2.png"></p> <h2 id="浏览器兼容性">浏览器兼容性</h2> <div>{{CompatibilityTable}}</div> <div id="compat-desktop"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Chrome</th> <th>Firefox (Gecko)</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari</th> </tr> <tr> <td>Basic support</td> <td>1</td> <td>{{CompatGeckoDesktop(1.0)}}</td> <td>9</td> <td>9</td> <td>3</td> </tr> </tbody> </table> </div> <div id="compat-mobile"> <table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Android</th> <th>Firefox Mobile (Gecko)</th> <th>IE Mobile</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>1</td> <td>{{CompatGeckoMobile(1.0)}}</td> <td>9</td> <td>9</td> <td>3</td> </tr> </tbody> </table> </div> <h3 id="Gecko_note" name="Gecko_note">Gecko 备注</h3> <p>从 Firefox 4 到 Firefox 24,该属性有 bug,而且某种情况下,会在页面加载前给出一个错误的值,查看 {{bug(641188)}}。</p> <h2 id="Standards_information" name="Standards_information">标准相关信息</h2> <p>DOM Level 0。不属于任何 W3C 技术规范或推荐。</p> <h2 id="See_also" name="See_also">相关链接</h2> <ul> <li>{{domxref("window.innerWidth")}}</li> <li>{{domxref("window.outerHeight")}}</li> <li>{{domxref("window.outerWidth")}}</li> </ul>