Code2care : TechZone Apps & Tutorials

Get Device Screen Width and Height using javaScript



To get the height and width of the Display Screen we must use screen.height and screen.width javascript properties respectively. The screen property is available in the Window Object, we don't need to prefix it with screen though.

getScreenDimentions.html
<!DOCTYPE html>
<html>
<title>Get Device width and Height using Javscript</title>

<script type="text/javascript">

function getScreenDimentions() {
document.getElementById("dimenstions").innerHTML = 
"Display Width : " + screen.width +"<br/> Display Height : " + screen.height;
}
</script>


<h2>You Monitor display pixels</h2> 
<body onload="getScreenDimentions()">

<div id="dimenstions"></div>



</body>
</html>



To demonstrate we create an javaScript function in the head section getScreenDimentions() and set the screen width and height to the html div element with class name dimensions on body load.

screen dimentions output


Note that the screen property returns the dimensions in unit pixel.










Top




Posts related to javascript.


1. Top 15 Programming Languages to learn 2014-2015

2. How to detect Browser and Operating System Name and Version using javaScript

3. How to make jsfiddle bootstrap ready

4. Detect if Cookies are enabled using javascript

5. How to get UTC (GMT) using javascript

6. Add Animated Scrolling to Html Page Title Script

7. Loading previous page using html button using javascript

8. Get Device Screen Width and Height using javaScript

9. Digital clock example using javaScript with Source code

    more...






Popular tags
android
x 175
eclipse
x 29
notepadplusplus
x 20
macosx
x 14
sharepoint
x 14
html
x 14
mac
x 13
androidstudio
x 11




1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


Code2care © 2012-17