Use documentElement to correctly obtain the size of the current visible area. documentelement

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.