Different browser JS get browser height and width

Source: Internet
Author: User

Excerpt from: http://blog.csdn.net/lai_gb/archive/2009/07/04/4320956.aspx

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 ==> 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)

There is no standard for defining the

IE is:

Document.documentElement.clientWidth ==> 0

Document.documentElement.clientHeight ==> 0

Firefox is:

Document.documentElement.clientWidth ==> Page object width (i.e. body object width plus margin) Document.documentElement.clientHeight = = > Page object height (i.e. body object height plus margin)

Opera is:

Document.documentElement.clientWidth ==> Page object width (i.e. body object width plus margin) Document.documentElement.clientHeight = = > Page object height (i.e. body object height plus margin)

Web page Visible area width: document.body.clientWidth

Web page Visible Area height: document.body.clientHeight

Web page Visible Area width: document.body.offsetWidth (including edge width)

Web page Visible Area High: document.body.offsetHeight (including edge height)

Page body Full text width: document.body.scrollWidth

Page body Full text High: Document.body.scrollHeight

Page is rolled away High: document.body.scrollTop

Webpage is rolled away 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 work area height: window.screen.availHeight

Screen available work area 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 computed top position of the object relative to the layout or the parent coordinate specified by the OffsetTop property

Event.clientx horizontal coordinates of relative documents

Event.clienty vertical coordinates of relative documents

Event.offsetx horizontal coordinates relative to the container

Event.offsety the vertical coordinate of the relative container

Document.documentElement.scrollTop The vertical scrolling value

Event.clientx+document.documentelement.scrolltop horizontal coordinates of relative documents + amount of vertical scrolling

Implementation code

<! 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>

<H2 align= "center" > Please resize the browser window

<form action= "#" method= "Get" Name= "Form1" Id= "Form1" >

<!--show the actual size of the browser window--

Actual height of browser window: <input type= "text" name= "availheight" size= "4"/><br/>

Actual width of browser window: <input type= "text" name= "availwidth" size= "4"/><br/>

</form>

<script type= "Text/javascript" >

<!--

var winwidth = 0;

var winheight = 0;

function finddimensions ()//functions: Getting dimensions

{

Get window width

if (window.innerwidth)

Winwidth = window.innerwidth;

else if ((document.body) && (document.body.clientWidth))

Winwidth = Document.body.clientWidth;

Get window Height

if (window.innerheight)

Winheight = Window.innerheight;

else if ((document.body) && (document.body.clientHeight))

Winheight = Document.body.clientHeight;

Get the window size by examining the body inside the document

if (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 a function to get a value

Window.onresize=finddimensions;

-

</script>

</body>


This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/lai_gb/archive/2009/07/04/4320956.aspx

Different browser JS get browser height and width

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.