JS get browser height and width

Source: Internet
Author: User

。 If so, the values of Document.documentElement.clientWidth and document.documentElement.clientHeight are used respectively. Otherwise, the values of Document.body.clientWidth and document.body.clientHeight are used.

var pagewidth = window.innerwidth,
var pageheight = window.innerheight;
if (typeof pagewidth!= "number") {
if (Document.compatmode = = "Number") {
PageWidth = Document.documentElement.clientWidth;
PageHeight = Document.documentElement.clientHeight;
}else{
PageWidth = Document.body.clientWidth;
PageHeight = Document.body.clientHeight;
}
}

The standard of the consortium is as follows

In IE:
Document.body.clientWidth ==> Body Object width
Document.body.clientHeight ==> Body Object Height
Document.documentElement.clientWidth ==> Visible Area width
Document.documentElement.clientHeight ==> Visible Area height
In Firefox:
Document.body.clientWidth ==> Body Object width
Document.body.clientHeight ==> Body Object Height
Document.documentElement.clientWidth ==> Visible Area width
Document.documentElement.clientHeight ==> Visible Area height

Opera in:
Document.body.clientWidth ==> Visible Area width
Document.body.clientHeight ==> Visible Area height
Document.documentElement.clientWidth ==> Page Object width (that is, the body object width plus margin width)
Document.documentElement.clientHeight ==> Page Object height (that is, height of the body object plus margin high)

The following diagram illustrates

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.