Viewport dimensions | Javascript

var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0); var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0); console.log(w); // w - viewport width console.log(h); // h - viewport height
Viewport Size In JavaScript.

jsFiddle example -
The example will take the botom-right window which is an iframe, that is why the values are smaller than your browser's viewport.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.