Javacript get current screen size _javascript tips

Source: Internet
Author: User

When using HTML5 to do development under Android, to get the actual size of the screen, directly on the code, you can pass the following code test.

Copy Code code as follows:
<script>
function A () {
document.write (
"Screen resolution is:" +screen.width+ "*" +screen.height
+ "<br/>" +
"Screen Available size:" +screen.availwidth+ "*" +screen.availheight
+ "<br/>" +
"Page visible area wide:" +document.body.clientwidth
+ "<br/>" +
"Page visible Area High:" +document.body.clientheight
+ "<br/>" +
"The visible area of the Web page is wide (including the width of the sideline):" +document.body.offsetwidth
+ "<br/>" +
"High page visible area (including edge width):" +document.body.offsetheight
+ "<br/>" +
"Page body Full text width:" +document.body.scrollwidth
+ "<br/>" +
"The full text of the Web page is high:" +document.body.scrollheight
+ "<br/>" +
"The Web page is rolled away High:" +document.body.scrolltop
+ "<br/>" +
"The pages were rolled away to the left:" +document.body.scrollleft
+ "<br/>" +
On the body part of the Web page: +window.screentop
+ "<br/>" +
"Page body part left:" +window.screenleft
+ "<br/>" +
"High screen resolution:" +window.screen.height
+ "<br/>" +
"Width of screen resolution:" +window.screen.width
+ "<br/>" +
"Screen available workspace height:" +window.screen.availheight
+ "<br/>" +
"Screen Available workspace width:" +window.screen.availwidth
);
}
</script>
<body onload= "A ()" >
</body>

HTML Precise positioning: Scrollleft,scrollwidth,clientwidth,offsetwidth

ScrollHeight: Gets the scrolling height of the object.
ScrollLeft: Sets or gets the left distance between the left edge of an object and the current visible content in the window
ScrollTop: Sets or gets the distance between the top of the object and the topmost part 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 coordinates specified by the Offsetparent property
offsettop: Gets the calculated top position of the object relative to the layout or the parent coordinates specified by the offsettop property
Event.clientx the horizontal coordinates of the relative document
Event.clienty vertical coordinates relative to document
The horizontal coordinates of the event.offsetx relative to the container
The vertical coordinates of the event.offsety relative to the container
Document.documentElement.scrollTop The vertical scrolling value
Event.clientx+document.documentelement.scrolltop relative to the document's horizontal coordinates + vertical scrolling amount

Ie,firefox differences are as follows:

IE6.0, ff1.06+:
clientwidth = width + padding
clientheight = height + padding
offsetwidth = width + padding + border
offsetheight = height + padding + border

ie5.0/5.5:

ClientWidth = Width-border
ClientHeight = Height-border
offsetwidth = width
offsetheight = height

(Need to mention: CSS in the margin attribute, and clientwidth, Offsetwidth, clientheight, offsetheight are irrelevant)

Page visible area wide: document.body.clientWidth
Page visible Area High: document.body.clientHeight
Web page Visible area wide: document.body.offsetWidth (including edge width)
Page visible Area High: document.body.offsetHeight (including edge height)
Page body Full text width: document.body.scrollWidth
The full text of the Web page High: document.body.scrollHeight
Web pages are rolled up high: Document.body.scrollTop
Pages were rolled away to the left: Document.body.scrollLeft
Web 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

The above is the use of javacript to get the current screen size of the entire content, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.