screen size change?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

screen size change?

Post by gavinbsocom »

where and how would i put the code to choose a page depending on a persons screen size? can i do it all in php?

<?php
$switch = "screensize";

if screensize > 1024
header('location:default.php');
if screensize < 1024
header('location:default2.php');
endif
endif
?>

is something like that even possible, im new to this, and reading this book over and over.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

can i do it all in php?
nope, you need to use JavaScript to find out the users resolution (just bear in mind that the resolution has no bearing on how big or small the user has made the browser window). If you search this forum for javascript and resolution then you'll find where others have asked the same or similar questions and received code snippets.

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Try not to use the alternative syntax for control structures in PHP, very few people use it and braces are just so much clearer to read:

Code: Select all

if ($screensize > 1024) {
    header('location:default.php');
} elseif ($screensize < 1024) {
    header('location:default2.php');
}
Mac
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post by gavinbsocom »

dont you hav eto close those if's?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Nope. You do that by using the braces. if (X == Y) { <- start ... end -> }

PHP itself sees the start and end (so to speak).
I would take the opportunity to lift out that you should try to use the paranthesis also, as in Mac's example.

As Mac state, using alternate syntax is messy. And if you learn the correct way of typing (if I might say so) you will have much, much easier time spotting your own mistakes in the future. Trust me.

Do you happen to come from a background using VB(A)?
gavinbsocom
Forum Commoner
Posts: 71
Joined: Tue Sep 30, 2003 9:51 pm

Post by gavinbsocom »

k thankyou. Ill mess with the javascript portion of it, or i was thinking setting hte page = to like 700px so then if someone had 800 x 600 it fit them and if htey had 1024x 768 it fit them...
Post Reply