Forum Moderators: open

Message Too Old, No Replies

How to handle user with javascript disabled

with resolution elements

         

ajs83

8:27 pm on Jul 25, 2005 (gmt 0)

10+ Year Member



I want to be able to send users with 800x600 to one page and users with 1024x768 & higher to another using the code below

script language="Javascript1.1">
function detect(){
if(screen.width<1024¦¦screen.height<768){
location.href('hi.php');
}else{
location.href('lo.html');
}

}
</script>

But I also want to be able to properly allow users with javascript disabled to view the lower end page. Whats the best way to accomplish this?

tedster

10:28 pm on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can just serve the low resolution page by default. If the script you pasted in above is called from lo.html then everything is fine -- you don't even need an "else" statement.

In fact, this is an important principle, IMO, and not just with scrfeen res. So many scripts try to accommodate every possible situation with an explicit direction, and you often cannot think of everything. It's much better to serve the most common situation by default. I use principle this when I need browser detection, Flash detection, and so on.

<added>
you might want to use the replace() method instead of just reassigning location.href to a new document. That will keep the Back Button from being frustrating for your visitors who have been redirected -- and that will be in the area of 70% as you have set up the logic her.
</added>

ajs83

12:30 am on Jul 26, 2005 (gmt 0)

10+ Year Member



Thanks!

Would similar code work if I tell it to use a different style sheet instead of redirecting a user to another page?

tedster

1:39 am on Jul 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure - and if your layout can accommodate it, that's probably a better way. Even better still would be to create a "liquid layout" css that uses % for at least one element and therefore flows with different resolutions and maxes at 1000px wide.

ajs83

2:00 am on Jul 26, 2005 (gmt 0)

10+ Year Member



Thanks!

I'm just getting the basics of CSS down and know the two sheet method isn't the best, but I figure it's a start.