...

View Full Version : JavaScript Redirect Has Problems



abannet
05-11-2005, 10:14 PM
I'm working on a redirect script, where the script sends you to a page based on your resolution. I have tried everything I have found on the internet from:

window.location
window.location.href
document.location
document.location.href
location.replace
self.location

In any case, I was hoping that someone could show me the problem.



if ((screen.width == 640) && (screen.height == 480))
alert("Your resolution must be at least 800x600");
else if ((screen.width == 800) && (screen.height == 600))
document.location.href = "theater800x600.html";
else if ((screen.width == 1024) && (screen.height == 768))
document.location.href = "theater1024x768.html";
else if ((screen.width == 1152) && (screen.height == 864))
document.location.href = "theater1152x864.html";
else if ((screen.width == 1280)) && (screen.height == 720))
document.location.href = "theater1280x720.html";
else if ((screen.width == 1280) && (screen.height == 768))
document.location.href = "theater1280x768.html";
else if ((screen.width == 1280) && (screen.height == 960))
document.location.href = "theater1280x960.html";
else if ((screen.width == 1280) && (screen.height == 1024))
document.location.href = "theater1280x1024.html";
else if ((screen.width == 1360) && (screen.height == 768))
document.location.href = "theater1360x768";
else if ((screen.width == 1600) && (screen.height == 900))
document.location.href = "theater1600x900.html";
else if ((screen.width == 1600) && (screen.height == 1024))
document.location.href = "theater1600x1024.html";
else if ((screen.width == 1600) && (screen.height == 1200))
document.location.href = "theater1600x1200.html";
else if ((screen.width == 1920) && (screen.height == 1080))
document.location.href = "theater1920x1080.html";
else if ((screen.width == 1920) && (screen.height == 1200))
document.location.href = "theater1920x1200.html";
else if ((screen.width == 1920) && (screen.height == 1440))
document.location.href = "theater1920x1440.html";
else if ((screen.width == 2048) && (screen.height == 1534))
document.location.href = "theater2048x1534.html";
else alert("The maximum size that this page supports is 2048x1534. Please adjust your resolution.");


I have the <SCRIPT></SCRIPT> and all that, but this is the main part.

Cheers.

rwedge
05-12-2005, 12:35 AM
You have an extra ) in this line :
else if ((screen.width == 1280)) && (screen.height == 720))
document.location.href = "theater1280x720.html"; I would use location.replace or reload, otherwise when someone hits their back button on the theater page they will be in a loop - the redirect page will send them back to the theater page.

/Bob

abannet
05-12-2005, 01:49 AM
Thanks for the help.

Cheers.
-Alan



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum