JS Get page width and Height value instance

Source: Internet
Author: User

See the difference use the following code

The code is as follows Copy Code

Alert (page visible area wide: document.body.clientWidth: "+ document.body.clientWidth +" N page visible Area High: document.body.clientHeight: "+ Document.body.clientHeight + "N page visible area wide: document.body.offsetWidth (including edge width):" + document.body.offsetWidth + "N page visible area High: Document.body.offsetHeight (including the edge of the high): "+ Document.body.offsetHeight +" n the text full text width: document.body.scrollWidth: "+ Document.body.scrollWidth + "N page text High: document.body.scrollHeight:" + document.body.scrollHeight + "n pages are rolled high: Document.body.scrollTop: "+ Document.body.scrollTop +" n pages are rolled away to the left: Document.body.scrollLeft: "+ Document.body.scrollLeft + "N page body part: window.screentop:" + window.screentop + "N page body part left: window.screenleft:" + Window.screenleft + "N screen resolution High: Window.screen.height:" + window.screen.height + "N Screen resolution width: window.screen.width:" + window . screen.width + "n Screen available workspace height: window.screen.availHeight:" + window.screen.availHeight + "N Screen available workspace width: Window.screen.availWidth: "+ window.screen.availWidth);

Use the following code if used

The code is as follows Copy Code

Alert (page visible area wide: document.body.clientWidth: "+document.body.clientwidth");
Alert ("Page visible area High: document.body.clientHeight:" +document.body.clientheight);
Alert ("Page visible area wide: document.body.offsetWidth (including edge width):" +document.body.offsetwidth);
Alert ("Page visible area High: Document.body.offsetHeight (including edge):" +document.body.offsetheight);
Alert ("Web page body Full text width: document.body.scrollWidth:" +document.body.scrollwidth);
Alert ("The full text of the Web page: document.body.scrollHeight:" +document.body.scrollheight);
Alert ("Web page is rolled up high: Document.body.scrollTop:" +document.body.scrolltop);
Alert ("Web page is rolled away left: document.body.scrollLeft:" +document.body.scrollleft);
Alert ("Page body part: window.screentop:" +window.screentop);
Alert ("Page body part left: window.screenleft:" +window.screenleft);
Alert ("High screen resolution: Window.screen.height:" +window.screen.height);
Alert ("width of screen resolution: Window.screen.width:" +window.screen.width);
Alert ("Screen available workspace height: window.screen.availHeight:" +window.screen.availheight);
Alert ("Screen available workspace width: window.screen.availWidth:" +window.screen.availwidth);

The following is displayed directly at the specified location in the HTML page

The code is as follows Copy Code

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>js get height and width summary </title>
<meta content= "Text/html;charset=utf-8" http-equiv= "Content-type"/>
<script type= "Text/javascript" src= "Js/jquery-1.5.2.js" ></script>
<script type= "Text/javascript" >
$ (document). Ready (function ()
{
Alert ("Browser current window visual area height:" +$ (window). Height ()); Browser current window visual area height
Alert ("Height of the browser's current window document:" +$ (document). Height ()); The height of the browser's current window document
Alert ("The height of the body of the browser's current window document:" +$ (document.body). Height ());//browser Current window document body level
Alert (the total height of the document body for the browser's current window includes border padding margin: +$ (document.body). Outerheight (True));//browser Current window document body's total height including border padding margin
Alert ("Browser current window viewable area width:" + ($ (window). Width ())); Browser current window visual area width
Alert ("Browser's current Window Document object width:" +$ (document). width ());//browser Current window Document object widths
Alert (the height of the body of the browser's current window document: +$ (document.body). width ());//browser Current window document body height
Alert ("Browser Current window document body total width includes border padding margin:" +$ (document.body). Outerwidth (True); The total width of the body of the browser's current window document includes the border padding margin
Alert ("Display resolution, height can only be obtained with JavaScript code:" +screen.height);//monitor resolution, can only be obtained with JavaScript code
Alert ("Display resolution, can only get width in JavaScript code:" +screen.width);
})  ;


</script>

<body>
<ul>
<li> page Visible area wide: Document.body.clientWidth </li>
<li> page Visible Area High: Document.body.clientHeight </li>
<li> page Visible area wide: document.body.offsetWidth (including edge width) </li>
<li> page Visible Area High: document.body.offsetHeight (including the edge of the high) </li>
<li> Web page Full text width: document.body.scrollWidth </li>
<li> page Full text High: Document.body.scrollHeight </li>
<li> pages are rolled up high: Document.body.scrollTop </li>
<li> pages are rolled away to the left: Document.body.scrollLeft </li>
<li> main body part: Window.screentop </li>
<li> Homepage Body part left: Window.screenleft </li>
<li> screen resolution High: window.screen.height</li>
<li> screen resolution width: Window.screen.width </li>
<li> Screen Available workspace height: window.screen.availheight</li>
<li> screen Available workspace width: window.screen.availWidth </li>
</ul>

</body>

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.