Javascript to get Summary of webpage width and height, javascript to get summary

Source: Internet
Author: User

Javascript to get Summary of webpage width and height, javascript to get summary

Document. body. clientWidth-visible area width of the webpage
Document. body. clientHeight-the visible area of the webpage is high.

Document. body. offsetWidth-visible area width of the webpage, including the width of the edge and scroll bar
Document. body. offsetHeight-the visible area of the webpage is high, including the height of the edge and the scroll bar. [FF, The chrom is the whole page height, and the IE opera is normal]

Document. body. scrollWidth-total webpage width
Document. body. scrollHeight-total webpage height

Document. body. scrollTop-when there is a scroll bar, drag down the scroll bar, the height of the part not shown above
Document. body. scrollLeft-Same as above

Window. innerHeight-the internal height of the browser window

Window. innerWidth-the internal width of the browser window

Window. screenTop-the distance from the top of the webpage document to the top of the screen, but FF does not support it. The performance of Chrom, IE, and Opera varies with caution.]
Window. screenLeft-left part of the webpage body [the leftmost side of the webpage document is the leftmost side distance from the screen, but FF does not support it. The performance of Chrom, IE, and Opera is different. Use it with caution]

Window. screen. height-screen resolution height
Window. screen. width-width of the screen resolution

Window. screen. availHeight-available workspace height [entire screen, excluding the taskbar below]
Window. screen. availWidth-available workspace width [width of the entire screen]

Window. screen. clorDepth-screen color, commonly used 16-bit, 32-bit, etc.
Window. screen. deviceXDPI-screen pixels/inches [supported by IE, not supported by others]

How to obtain the page width by using JavaScript

<Script> function getInfo () {var s = ""; s + = "visible area width:" + document. body. clientWidth; s + = "visible area of the webpage high:" + document. body. clientHeight; s + = "visible area width of the webpage:" + document. body. offsetWidth + "(including the width of the edge and scroll bar)"; s + = "visible area of the webpage Height:" + document. body. offsetHeight + "(including edge width)"; s + = "webpage text width:" + document. body. scrollWidth; s + = "webpage text Height:" + document. body. scrollHeight; s + = "the height of the page to which the page is rolled (ff):" + document. body. scrollTop; s + = "high page volume (ie):" + document.doc umentElement. scrollTop; s + = "left when the webpage is rolled:" + document. body. scrollLeft; s + = "webpage body part:" + window. screenTop; s + = "webpage body section left:" + window. screenLeft; s + = "high screen resolution:" + window. screen. height; s + = "Screen Resolution width:" + window. screen. width; s + = "available workspace height of the screen:" + window. screen. availHeight; s + = "available workspace width:" + window. screen. availWidth; s + = "your screen setting is" + window. screen. colorDepth + "bit color"; s + = "Your Screen Settings" + window. screen. deviceXDPI + "pixels/inches"; // alert (s);} getInfo (); </script>

In my local test:
It can be used in IE, FireFox, and Opera

document.body.clientWidthdocument.body.clientHeight

It is very simple and convenient.
In the company's projects:
Opera is still in use

document.body.clientWidthdocument.body.clientHeight

However, IE and FireFox use

document.documentElement.clientWidthdocument.documentElement.clientHeight

It turned out to be W3C standards.

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
If this line is added to the page

In IE:

Document. body. clientWidth => BODY object width document. body. clientHeight => bodyobject height document.doc umentElement. clientWidth => wide distance document.doc umentElement. clientHeight => visible area height

In FireFox:

Document. body. clientWidth => BODY object width document. body. clientHeight => bodyobject height document.doc umentElement. clientWidth => wide distance document.doc umentElement. clientHeight => visible area height

In Opera:

Document. body. clientWidth => visible area width document. body. clientHeight ==> zookeeper High Level document.doc umentElement. clientWidth ==> Page Object width (that is, the bodyobject width is added to the marginwidth extension document.doc umentElement. clientHeight => Page Object height (that is, the height of the BODY object plus the Margin height)


If W3C standards are not defined

IE:

document.documentElement.clientWidth ==> 0document.documentElement.clientHeight ==> 0

FireFox:
Copy codeThe Code is as follows: document.doc umentElement. clientWidth => Page Object width (that is, the width of the BODY object plus the Margin width)
Document.doc umentElement. clientHeight ==> Page Object height (that is, the height of the BODY object plus the Margin height)

Opera:

Copy codeThe Code is as follows: document.doc umentElement. clientWidth => Page Object width (that is, the width of the BODY object plus the Margin width)
Document.doc umentElement. clientHeight ==> Page Object height (that is, the height of the BODY object plus the Margin height)

The above is all the content of this article. I hope you will like it.

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.