A function of JavaScript to get the visual height and width of the current page

Source: Internet
Author: User

    function getpagesize () {        var  xscroll,yscroll;        if  (window.innerheight &&  window.scrollmaxy) {            xscroll  = window.innerwidth + window.scrollmaxx;             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...would also work in explorer 6 strict, mozilla and  Safari            xScroll =  Document.body.offsetwidth;            yscroll  = document.body.offsetHeight;        }         var windowWidth, windowHeight;         if  (self.innerheight) { // all except explorer             windowWidth = self.innerWidth;             windowHeight = self.innerHeight;         }        else if  (document.documentelement &&  Document.documentElement.clientHeight) {        // explorer 6  strict mode            windowwidth  = document.documentElement.clientWidth;             windowHeight = document.documentElement.clientHeight;         }        else if  (document.body) {//  other explorers            windowwidth =  document.body.clientWidth;             windowheight = document.body.clientheight;        }          // for small pages with total height less then height  of the viewport        var pageWidth,pageHeight;         if (yscroll < windowheight) {             pageHeight = windowHeight;         }else{             pageheight = yscroll;        }         if (xscroll < windowwidth) {             pagewidth = windowwidth;        } else{            pagewidth = xscroll;         }        return {              "PageWidth":p agewidth,              "PageHeight":p ageheight        }     }//alert (GetPageSize (). PageHeight)

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.