Thursday, September 22, 2011

JavaScript/PHP Change an Image Depending On Visitors' Screen Resolution?

How can I use either JavaScript or PHP to detect the visitor's screen resolution and change the header image accordingly?JavaScript/PHP Change an Image Depending On Visitors' Screen Resolution?
*Updated*



You actually only need one header file.



From there you can just use the following script to determine which width of header image to use:



%26lt;HTML%26gt;

%26lt;TITLE%26gt;Your Site%26lt;/TITLE%26gt;

%26lt;HEAD%26gt;

%26lt;?

if(isset($HTTP_COOKIE_VARS[';users_reso?br>
{$screen_res = $HTTP_COOKIE_VARS[';users_resolution';];}

else

{

?%26gt;

%26lt;script language=';javascript';%26gt;

writeCookie();



function writeCookie()

{

var the_cookie = ';users_resolution=';+ screen.width + ';x'; + screen.height;

document.cookie=the_cookie

location=header.php

}

%26lt;/script%26gt;

%26lt;?

}

?%26gt;

%26lt;/HEAD%26gt;

%26lt;BODY%26gt;

%26lt;?php



$screenres_split=explode(';x';, $screen_res);

$screen_width=$screenres_split[0];

$screen_height=$screenres_split[1];



if ($screen_width%26lt;1024) {$banner_img='http://pratstercs.dailyhos?br>
else {$banner_img='http://pratstercs.dailyhos?br>


echo ';%26lt;img src=$banner_img%26gt;';;



?%26gt;

%26lt;/BODY%26gt;

%26lt;/HTML%26gt;JavaScript/PHP Change an Image Depending On Visitors' Screen Resolution?
Just use a % width/height instead of set pixels.
  • default myspace
  • hair cutting
  • No comments:

    Post a Comment