I googled this and got a quirksmode site that gives you your screen size. Pulling up the console I see that screen.width
and screen.height
are directly available from the window object.
I want to do the detection in pure JavaScript to get started. Can I use this property across all devices and browsers - mobile, tablet, PC and Chrome, Safari, IE, Firefox.
I don't care about the view port changing due to re-sizing etc. Just the actual size of the screen which does not change.
I was hoping there was a single property I could check across devices and browsers.
Here is some general info by wikipedia on responsive web design.
Check the browser window from 360×640 to 1920×1080 screen resolutions. Your page should score high on all criteria throughout the entire resolution range. Your page should also work at even smaller and bigger sizes, though such extremes are less important.
Screenfly is a free tool for testing a website on different screen sizes and different devices. It's been around for a few years now, but it's still popular and does its job extremely well. Just enter your URL, pick your device and screen size from the menus and you'll see how well your website is working on it.
Small (smaller than 640px) Medium (641px to 1007px) Large (1008px and larger)
The size of a 16:9 screen depends on how long the screen's diagonal is, as 16:9 is merely the ratio of the screen's width to its height. If you have the screens diagonal, you can multiply that measurement by 0.872 to get the screen's width. You can also multiply the diagonal by 0.49 to get the screen's height.
Take a look at Get the device width in javascript
Media Queries work in js too:
if (window.matchMedia('screen and (max-width: 768px)').matches) {}
Another way would be:
var width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With