Window innerWidth Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window innerWidth

Description

The innerWidth property returns the inner width of a window's content area.

The property is read-only.

Return Value

A Number, representing the inner width of the browser window's content area, in pixels

The following code shows how to get the window's height and width:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*  w w w  .j a v a2s  . co  m*/
    var w = window.innerWidth;
    var h = window.innerHeight;
    document.getElementById("demo").innerHTML = "Width: " + w + "<br>Height: " + h;
}
</script>

</body>
</html>
</html>

Related Tutorials