JS obtains the current webpage size and screen resolution. js currently

Source: Internet
Author: User

JS obtains the current webpage size and screen resolution. js currently

The effect is as follows:

The Code is as follows:

<Html> 

The code is illustrated as follows:


How can I obtain the screen width of a mobile phone from a js webpage?

</Head>

<P id = "p1"> sssss </p>
<Body>
</Body>
</Html>
<Script>
Var x = navigator;
Var w = window. innerWidth
| Document.doc umentElement. clientWidth
| Document. body. clientWidth;
Var h = window. innerHeight
| Document.doc umentElement. clientHeight
| Document. body. clientHeight;
Document. getElementById ("p1 "). innerHTML = "<B> screen resolution: </B>" + screen. width + "*" + screen. height + "<B> internal window </B>:" + w + "*" + h
</Script>
I don't know if it is the screen resolution: the desktop Resolution on the pc. The mobile phone is a fixed resolution of the model, such
The resolution of Huawei 8813 is 480*854 .. The internal window is to change the window size. Refresh the window and there will be new data.

How does HTML obtain screen size?

<Html>
<Script>
Function (){
Document. write (
"Screen Resolution:" + screen. width + "*" + screen. height // preferably window. screen
+ "<Br/>" +
"Available screen size:" + screen. availWidth + "*" + screen. availHeight
+ "<Br/>" +
"Visible area width of the webpage:" + document. body. clientWidth
+ "<Br/>" +
"Visible area Height:" + document. body. clientHeight
+ "<Br/>" +
"Visible area width of the webpage (including the width of the edge):" + document. body. offsetWidth
+ "<Br/>" +
"Visible area height (including edge width):" + document. body. offsetHeight
+ "<Br/>" +
"Webpage text width:" + document. body. scrollWidth
+ "<Br/>" +
"Webpage text Height:" + document. body. scrollHeight
+ "<Br/>" +
"Webpage volume Height:" + document. body. scrollTop
+ "<Br/>" +
"Left of the webpage to be rolled:" + document. body. scrollLeft
+ "<Br/>" +
"Webpage body part:" + window. screenTop
+ "<Br/>" +
"Webpage body part left:" + window. screenLeft
+ "<Br/>" +
"Screen Resolution height:" + window. screen. height
+ "<Br/>" +
"Screen Resolution width:" + window. screen. width
+ "<Br/>" +
"Available screen workspace Height:" + window. screen. availHeight
+ "<Br/>" +
"Available screen workspace width:" + window. screen. availWidth
);
}
Function set_bgColor (){
Document. body. style. backgroundColor = "red ";
}
Function set_bgImg (){
Document. body. style. backgroundImage = "url (t/JS to get... the rest of the text>

Related Article

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.