Obtain the height and width of the visible area of the browser window. For details about the height of the scroll bar, see.
IE, the browser display window size can only be obtained below: the code is as follows: copy the code
Copy codeThe Code is as follows:
Document. body. offsetWidth
Document. body. offsetHeight
In the declared DOCTYPE browser, you can get the Browser display window size: the code is as follows: copy the code
Copy codeThe Code is as follows:
Document.doc umentElement. clientWidth
Document.doc umentElement. clientHeight
IE, FF, and Safari support this method. Although opera supports this attribute, the page size is returned;
Besides IE, all browsers save this information in the window object. You can use the following command to obtain the information: copy the Code as follows:
Copy codeThe Code is as follows:
Window. innerWidth
Window. innerHeight
The general method for obtaining the entire webpage size is as follows: copy the code
Copy codeThe Code is as follows:
Document. body. scrollWidth
Document. body. scrollHeight
The screen resolution height is generally obtained using the following code: copy the code
Copy codeThe Code is as follows:
Window. screen. height
Window. screen. width
Summary examples
Copy codeThe Code is as follows:
Function getViewSizeWithoutScrollbar () {// does not contain a scroll bar
Return {
Width: document.doc umentElement. clientWidth,
Height: document.doc umentElement. clientHeight
}
}
Function getViewSizeWithScrollbar () {// contains the scroll bar
If (window. innerWidth ){
Return {
Width: window. innerWidth,
Height: window. innerHeight
}
} Else if(document.doc umentElement. offsetWidth = document.doc umentElement. clientWidth ){
Return {
Width: document.doc umentElement. offsetWidth,
Height: document.doc umentElement. offsetHeight
}
} Else {
Return {
Width: document.doc umentElement. clientWidth + getScrollWith (),
Height: document.doc umentElement. clientHeight + getScrollWith ()
}
}
}
The differences between IE and FireFox are as follows:
IE6.0, FF1.06 +:
Copy codeThe Code is as follows:
ClientWidth = width + padding
ClientHeight = height + padding
OffsetWidth = width + padding + border
OffsetHeight = height + padding + border
IE5.0/5.5:
ClientWidth = width-border
ClientHeight = height-border
OffsetWidth = width
OffsetHeight = height
The following is the most common method for retrieving the entire page width (jquery framework is required ).
Copy codeThe Code is as follows:
$ (Document). width () <$ ('body'). width ()? $ (Document). width (): $ ('body'). width ();
$ (Document). height () <$ ('body'). height ()? $ (Document). height (): $ ('body'). height ();
Alert ($ (window). height (); // The height of the visible area of the current window in the browser
Alert ($ (document). height (); // The height of the current window document in the browser
Alert ($ (document. body). height (); // The height of the current window body in the browser
Alert ($ (document. body). outerHeight (true); // the total height of the current window document body in the browser includes border padding margin
Alert ($ (window). width (); // The width of the visible area of the current window in the browser
Alert ($ (document). width (); // The image width of the window document in the browser
Alert ($ (document. body). width (); // The height of the current window body in the browser
Alert ($ (document. body). outerWidth (true); // The total width of the current window body in the browser includes border padding margin
Alert ($ (document). scrollTop (); // gets the vertical height from the scroll bar to the top.
Alert ($ (document). scrollLeft (); // gets the vertical width from the scroll bar to the left.