JavaScript to get the window height and width

Source: Internet
Author: User
JavaScript to get the window height and width

Visible area width of the webpage: "+ document. Body. clientwidth;
Visible area Height: "+ document. Body. clientheight;
Visible area width of the webpage: "+ document. Body. offsetwidth +" (including the width of the edge and scroll bar )";
Visible area height of the webpage: "+ document. Body. offsetheight +" (including the width of the edge )";
Webpage text width: "+ document. Body. scrollwidth;
Webpage text Height: "+ document. Body. scrollheight;
Page size: "+ document. Body. scrolltop;
Left of the webpage to be rolled: "+ document. Body. scrollleft;
On the webpage body part: "+ window. screentop;
Left part of the webpage body: "+ window. screenleft;
Screen Resolution Height: "+ window. Screen. height;
Screen Resolution width: "+ window. Screen. width;
Available screen workspace Height: "+ window. Screen. availheight;
Available screen workspace width: "+ window. Screen. availwidth;
Your screen is set to "+ window. Screen. colordepth +" bit color ";
Your Screen Settings "+ window. Screen. devicexdpi +" pixel/Inch ";

Special 1,
Solution to document. Body. scrolltop with a total of 0
VaR scrollpos;
If (typeof window. pageyoffset! = 'Undefined '){
Scrollpos = Window. pageyoffset;
}
Else if (typeof document. compatmode! = 'Undefined '&&
Document. compatmode! = 'Background '){
Scrollpos = document.doc umentelement. scrolltop;
}
Else if (typeof document. Body! = 'Undefined '){
Scrollpos = Document. Body. scrolltop;
}
Alert (scrollpos );

Special 2,
Webpage text width: "+ document. Body. scrollwidth;
Webpage text Height: "+ document. Body. scrollheight;
If the preceding functions cannot be obtained, use the following method.
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;
}

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.