Page 1 of 1

Screen resolution

Posted: Thu Aug 18, 2005 1:12 pm
by tanaka
Is it possible to take info about user's screen resolution, put it on a variable and do something as

if($screen==800x600){
do something}
else{
do other thing}

?

Posted: Fri Aug 19, 2005 7:21 am
by Lixas
yes, it is possible, but not with php. U should use client side scripting language- javascript:

Code: Select all

<SCRIPT language="JavaScript">
<!-- this javascript code is right, but i dont say exactly same about syntax. Review it if it will not work

window.location='resolution.php?w='+screen.width+'&h='+screen.height; 

//-->
</SCRIPT>
in page resolution.php u will have global variables $w and $h with screen resulution
Browser Compatibility: NS 4+, IE 5+, Firefox

Taken and edited from http://www.pageresource.com/jscript/jscreen.htm

Posted: Fri Aug 19, 2005 2:03 pm
by tanaka
Wow, that's nice stuff.
Thanks Lixas

Posted: Fri Aug 19, 2005 5:33 pm
by Lixas
no problem, i allways help then i can. It's nice, that i can help with my coding knowledge for someone....

Posted: Thu Aug 25, 2005 6:57 am
by toychoq
Why need to set screen resolution

Posted: Wed Feb 01, 2006 9:57 pm
by mzikawy
Thnx man it's really useful one

Posted: Tue Feb 07, 2006 5:22 pm
by Lixas
toychoq wrote:Why need to set screen resolution
Not to set screen resulotion, but to know it. I think you understood wrong. php natively can not obtain user's screen's resolution, but using javascript you can pass it to page via $_GET method if you will need. It's sometimes usefull

Posted: Sat Mar 11, 2006 7:39 am
by kaos_frack
toychoq wrote:Why need to set screen resolution
you really need to know
ex. to make sure the width fits the resolution
otherwise users hate scrolling
so they'll just close your page, and never return again