Use documentElement to correctly obtain the size of the current visible area. documentelement
Other methods are not applicable. Only this documentElement can correctly obtain the size of the current visible area.
var w = parseInt(document.documentElement.clientWidth);var h = parseInt(document.documentElement.clientHeight);
How does javascript obtain the height of the visible area of the webpage (excluding the Content Rolled by the scroll bar) is the height of the webpage content that you can see
You can refer to the following function. This function is used to obtain the complete page size (that is, the area you can see in the browser, excluding the area to be rolled by the scroll bar)
----------------------------- Js Code ---------------------------------------------------------
<Script>
Function GetPageSize (){
Var xScroll, yScroll;
If (window. innerHeight & window. scrollMaxY ){
XScroll = document. body. scrollWidth;
YScroll = window. innerHeight + window. scrollMaxY;
} Else if (document. body. scrollHeight> document. body. offsetHeight ){
XScroll = document. body. scrollWidth;
YScroll = document. body. scrollHeight;
} Else {
XScroll = document. body. offsetWidth;
YScroll = document. body. offsetHeight;
}
Var implements wwidth, implements wheight;
If (self. innerHeight ){
Required wwidth = self. innerWidth;
Optional wheight = self. innerHeight;
} Else if (document.doc umentElement & document.doc umentElement. clientHeight ){
Required wwidth = document.doc umentElement. clientWidth;
Required wheight = document.doc umentElement. clientHeight;
} Else if (document. body ){
Required wwidth = document. body. clientWidth;
Optional wheight = document. body. clientHeight;
}
If (yScroll <windowHeight ){
PageHeight = running wheight;
} Else {
PageHeight = yScroll;
}
If (xScroll <1_wwidth ){
PageWidth = required wwidth;
} Else {
PageWidth = xScroll;
}
ArrayPageSize = new Array (pageWidth, pageHeight, expires wwidth, expires wheight)
Return arrayPageSize;
}
Alert (GetPageSize (); ...... remaining full text>
How to Dynamically Retrieve the browser window size in JS
It generates an object. This object has a property called w, which is used to store the window width. h indicates the storage height.
In this way, the call width of the method similar to getViewSize () [w] can be used.
If you want to change dynamically, you can do this:
Var size = getViewSize ();
Window. onresize = function () {size = getViewSize ();}
In this way, the window size can be obtained through the size variable at any time.