JS get browser height and width values (multi-browser)

Source: Internet
Author: User

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 in opera:
Document.body.clientWidth ==> Visible Area width document.body.clientHeight ==> visible area height Document.documentElement.clientWidth ==> Page object width (i.e. body object width plus margin) Document.documentElement.clientHeight = = > The height of the page object (that is, the body object height plus margin) does not define the standard of the Web, ie is:
Document.documentElement.clientWidth ==> 0
Document.documentElement.clientHeight ==> 0 Firefox is:
Document.documentElement.clientWidth ==> The width of the page object (that is, the body object width plus the margin width)
Document.documentElement.clientHeight ==> Page Object height (i.e. body object height plus margin height)
Opera: Document.documentElement.clientWidth ==> width of the page object (that is, the body object width plus the margin width) Document.documentElement.clientHeight ==> Page Object height (i.e. body object height plus margin height)
Web page Visible area width: document.body.clientWidth
Page visible Area High: Document.body.clientHeight Web page Visible area width: document.body.offsetWidth (including edge width) web page visible Area High: Document.body.offsetHeight ( Height including edge) page body Full text width: document.body.scrollWidth page body Full text High: Document.body.scrollHeight page is rolled High: document.body.scrollTop Page is rolled away on the left: Document.body.scrollLeft page body part: Window.screentop page body part left: Window.screenleft High screen resolution: Window.screen.height Width of screen resolution: Window.screen.width Screen Available Workspace height: Window.screen.availHeight screen Available workspace width: window.screen.availWidth
HTML Precise positioning: Scrollleft,scrollwidth,clientwidth,offsetwidth
ScrollHeight: Gets the scroll height of the object. ScrollLeft: Sets or gets the distance between the left edge of the object and the leftmost of the currently visible content in the window
ScrollTop: Sets or gets the distance between the top of the object and the top of the visible content in the window scrollwidth: Gets the scrolling width of the object
Offsetheight: Gets the height of the object relative to the layout or parent coordinates specified by the parent coordinate OffsetParent property
Offsetleft: Gets the calculated left position of the object relative to the layout or the parent coordinate specified by the OffsetParent property
OffsetTop: Gets the calculated top position of the object relative to the layout or the parent coordinate specified by the OffsetTop property Event.clientx the horizontal coordinates of the relative document
Event.clienty the vertical coordinates of the relative document EVENT.OFFSETX relative to the container's horizontal coordinates event.offsety the vertical coordinate of the container document.documentElement.scrollTop the value of scrolling vertically
Event.clientx+document.documentelement.scrolltop the horizontal coordinates of the relative document + the amount of scrolling in the vertical direction implementation code

Copy CodeThe code is as follows:<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <title> Please adjust the browser window </title> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "> </meta><body>

<form action= "#" method= "Get" Name= "Form1" Id= "Form1" >
<!--display the actual size of the browser window-the actual height of the browser window: <input type= "text" name= "availheight" size= "4"/><br/> The actual width of the browser window: & Lt;input type= "text" name= "availwidth" size= "4"/><br/> </form>
<script type= "Text/javascript" > <!--var winwidth = 0;
var winheight = 0; function finddimensions ()//functions: Get Dimension {
Gets the window width if (window.innerwidth) winwidth = window.innerwidth;
else if ((document.body) && (document.body.clientWidth))
Winwidth = Document.body.clientWidth; Gets the window height if (window.innerheight) winheight = window.innerheight; else if ((document.body) && (document.body.clientHeight)) winheight = Document.body.clientHeight; Get the window size if the body is detected by deep inside the document (Document.documentelement && document.documentElement.clientHeight && document.documentElement.clientWidth) {winheight = document.documentElement.clientHeight; winwidth = Document.documentElement.clientWidth; }//Results output to two text boxes
Document.form1.availheight.value= Winheight;
Document.form1.availwidth.value= Winwidth; } finddimensions ();
Call the function, get the numerical window.onresize=finddimensions; -
</script> </body>

JS get browser height and width values (multi-browser)

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.