JS that accurately obtains the page, window height, and width

Source: Internet
Author: User

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) {// all but Explorer Mac
XScroll = document. body. scrollWidth;
YScroll = document. body. scrollHeight;
} Else {// Explorer Mac... wocould also work in Explorer 6 Strict, Mozilla and Safari
XScroll = document. body. offsetWidth;
YScroll = document. body. offsetHeight;
}

Var implements wwidth, implements wheight;
If (self. innerHeight) {// all privileges t Explorer
Required wwidth = self. innerWidth;
Optional wheight = self. innerHeight;
} Else if (document.doc umentElement & document.doc umentElement. clientHeight) {// Explorer 6 Strict Mode
Required wwidth = document.doc umentElement. clientWidth;
Required wheight = document.doc umentElement. clientHeight;
} Else if (document. body) {// other Explorers
Required wwidth = document. body. clientWidth;
Optional wheight = document. body. clientHeight;
}

// For small pages with total height less then height of the viewport
If (yScroll <windowHeight ){
PageHeight = running wheight;
} Else {
PageHeight = yScroll;
}

// For small pages with total width less then width of the viewport
If (xScroll <1_wwidth ){
PageWidth = required wwidth;
} Else {
PageWidth = xScroll;
}


ArrayPageSize = new Array (pageWidth, pageHeight, expires wwidth, expires wheight)
Return arrayPageSize;
}
I was lucky enough to find your stuff and helped me solve the problem. But after reading it carefully, it seems a big problem. It seems that the parameter value and name are not correct.
// For small pages with total height less then height of the viewport
If (yScroll <windowHeight ){
PageHeight = yScroll;
} Else {
PageHeight = running wheight;
}

// For small pages with total width less then width of the viewport
If (xScroll <1_wwidth ){
PageWidth = xScroll;
} Else {
PageWidth = required wwidth;
}

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.