---
title: Document.width
slug: Web/API/Document/width
translation_of: Web/API/Document/width
---
<div>{{APIRef("DOM")}} {{Obsolete_header}}</div>

<div class="note">
<p><strong>注意:</strong> 從 {{Gecko("6.0")}} 開始, <code>document.width 將不再被支援。取而代之的是 </code><code>document.body.clientWidth 。請參照: </code>{{domxref("element.clientWidth")}}.</p>
</div>

<p>傳回目前文件中,{{HTMLElement("body")}} 元素的寬度有多少像素。</p>

<p>Internet Explorer 不支援!</p>

<h2 id="Syntax" name="Syntax">語法</h2>

<pre class="syntaxbox"><em>pixels</em> = document.width;
</pre>

<h2 id="Example" name="Example">範例</h2>

<pre class="brush:js">function init() {
    alert("文件的寬度是 " + document.width + " 像素。");
}
</pre>

<h2 id="Alternatives" name="Alternatives">其他替代</h2>

<pre class="syntaxbox">document.body.clientWidth              /* &lt;body&gt; 的寬度 */
document.documentElement.clientWidth   /* &lt;html&gt; 的寬度 */
window.innerWidth                      /* 視窗的寬度 */
</pre>

<h2 id="Specification" name="Specification">規範於</h2>

<p>HTML5</p>

<h2 id="See_also" name="See_also">同時參考</h2>

<ul>
 <li>{{domxref("document.height")}}</li>
 <li>{{domxref("Element.clientWidth")}}</li>
 <li>{{domxref("Element.scrollWidth")}}</li>
</ul>