I'm having this weird problem in javascript when I try to do a simple redirect. Here is my code:
if (screen.width <= 640) { var referrer = "640x480.htm"; } else if (screen.width <= 800) { var referrer = "800x600.htm"; } else if (screen.width > 800) { var referrer = "larger.htm"; } alert ("Sending you to page"); top.location.replace (referrer);
No matter what the screen width is... it will always send you to larger.html. Any help is much appreciated
Re: Javascript Problem
if (screen.width <= 640) { var referrer = "640x480.htm"; } else {if (screen.width <= 800) { var referrer = "800x600.htm"; } else {if (screen.width > 800) { var referrer = "larger.htm"; } } } alert ("Sending you to page"); window.location=referrer;
Javascript Problem
Hmm, Triumph, you seem to have two extra closing braces.
First off, have you checked what the value for screen.width is?
var referrer = "larger.htm"; if (screen.width <= 640) { referrer = "640x480.htm";} else if (screen.width <= 800) { referrer = "800x600.htm"; } alert ("Screen Width:"+screen.width+"; Sending you to page "+referrer+" ..."); top.location.replace (referrer);
Javascript Problem
Hmm, Triumph, you seem to have two extra closing braces.
The code I posted works but is messy. I could have done it cleaner, I'm sure.
Javascript Problem
Ah! I see them
To be honest I see no reason why the code posted at the top shouldn't work. It will only set referrer to larger.htm if screen.width is greater than 800. Hence my point to check the screen.width value. I figure its has to be >800.
Javascript Problem
Ah! I see them![]()
To be honest I see no reason why the code posted at the top shouldn't work. It will only set referrer to larger.htm if screen.width is greater than 800. Hence my point to check the screen.width value. I figure its has to be >800. Yes, you are correct. Perhaps the original poster is changing the width of the browser window and not the screen resolution (which is what screen.width returns).
browser width
Hi Coder101,
Really having three pages to maintain is not a good idea.
You would be better off looking at min-width and max-width and expressions or scripts to get that working in IE.
Here's a working method of what you are trying. It might need a little refining.
var w=0; if(document.compatMode == "CSS1Compat"){ //IE Standard mode w =document.body.parentNode.clientWidth; }else if(document.currentStyle){ //IE Quirks Mode w =document.body.clientWidth; }else{ //Netscape w = window.innerWidth; } w=parseInt(w); if (w <= 640) { var referrer = "640x480.htm"; }else if (w<= 800) { var referrer = "800x600.htm"; }else if (w > 800) { var referrer = "larger.htm"; } alert ("Sending you to page"); top.location.replace (referrer);Hope that helps
Re: browser width
Hi Coder101,
Really having three pages to maintain is not a good idea.
