Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you get a users screen size/resolution using javascript?

Tags:

javascript

Is there a way to get the a users screen size/resolutions using javascript? I figured you probably can't use PHP to do this as it's server-side, but as javascript is client-side I thought it may be an option.

like image 826
JasonMortonNZ Avatar asked Apr 05 '12 04:04

JasonMortonNZ


People also ask

How do I find the user screen size?

Use window. innerWidth and window. innerHeight to get the current screen size of a page.

What function do you need to call to get the width of the screen Javascript?

availWidth property returns the width of the visitor's screen, in pixels, minus interface features like the Windows Taskbar.

Which of the following can be used to retrieve the width of the user's screen in pixels?

width read-only property returns the width of the screen in CSS pixels.

How do I find my screen size in pixels?

You can use window. innerHeight and window. innerWidth to get the size of the window for the web page as the user sees it.


1 Answers

Yes, you can use the following to print out the resolution for example:

<script type="text/javascript">
document.write(screen.width+'x'+screen.height);
</script>

Might not work in older browsers, but will in most recent ones.

More info here:

http://www.javascriptkit.com/howto/newtech3.shtml

like image 50
Phaedrus Avatar answered Sep 27 '22 20:09

Phaedrus