SoFunction
Updated on 2025-03-03

javascript get current screen size

When using html5 to develop under Android, to get the actual size of the screen and directly upload the code, you can pass the following code test.

Copy the codeThe code is as follows:
<html>
<script>
function a(){
(
"Screen resolution is: "++"*"+
+"<br />"+
"Screen available size: "++"*"+
+"<br />"+
"Visible area width of web page:"+
+"<br />"+
"Visible area height of web page:"+
+"<br />"+
"Visible area width of web page (including the width of edge):"+
+"<br />"+
"Visible area height (including the width of the edge):"+
+"<br />"+
"The full text of the web page is wide:"+
+"<br />"+
"The full text of the web page is high:"+
+"<br />"+
"The web page is rolled away high:"+
+"<br />"+
"The page is rolled away from the left:"+
+"<br />"+
"On the main part of the web page:"+
+"<br />"+
"The left part of the web page text:"+
+"<br />"+
"The screen resolution is high:"+
+"<br />"+
"Width of screen resolution:"+
+"<br />"+
"Screen Available Workspace Height:"+
+"<br />"+
"Screen available workspace width:"+
);
}
</script>
<body onload="a()" >
</body>
</html>

HTML precise positioning: scrollLeft, scrollWidth, clientWidth, offsetWidth

scrollHeight: Gets the scroll height of the object.
scrollLeft: Set or get the distance between the left boundary of the object and the leftmost end of the currently visible content in the window
scrollTop: Set or get the distance between the top of the object and the top of the visible content in the window
scrollWidth: Get the scroll width of the object
offsetHeight: Gets the height of the object relative to the layout or the parent coordinate specified by the parent coordinate offsetParent property
offsetLeft: Gets the calculated left position of the object relative to the layout or parent coordinates 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
Horizontal coordinates relative to the document
Vertical coordinates relative to the document
Horizontal coordinates relative to the container
Vertical coordinates relative to container
The value of scrolling vertically
+ Horizontal coordinates relative to the document + the amount of scrolling in the vertical direction

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

(It should be mentioned that the margin attribute in CSS has nothing to do with clientWidth, offsetWidth, clientHeight, and offsetHeight)

The visible area width of the web page:
The visible area height of the web page:
Width of visible area on the web page: (including the width of the edge line)
The visible area height of the web page: (including the height of the edge line)
The full text of the web page is:
The full text of the web page is high:
The web page is rolled out:
The left of the web page being rolled out:
On the main part of the page:
Left part of the web page text:
High screen resolution:
Width of screen resolution:
Screen Available Workspace Height:
Screen Available Workspace Width:

The above is all the content of using javascript to get the current screen size. I hope you can give you a reference and I hope you can support me more.