blob: 39eef5c184e6e5807bddfcc64c9094563e2513c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
---
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 /* <body> 的寬度 */
document.documentElement.clientWidth /* <html> 的寬度 */
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>
|