PDA

View Full Version : Using JS to switch pages



wanapitei
03-07-2008, 08:58 PM
Once I've used JavaScript to establish a variable, is there a way use a test of the variable to switch to a different page? For instance:


if(ie=1) goto http://www.mysite.com/iepage.html

Kind regards

Jas
03-07-2008, 09:22 PM
var ie = 1;

if(ie == 1){
window.location = "http://www.site.com/iepage.html";
}

wanapitei
03-07-2008, 10:08 PM
var ie = 1;

if(ie == 1){
window.location = "http://www.site.com/iepage.html";
}

Not working.

Full disclosure. The site I'm developing is using this site's Omnislide (http://www.dynamicdrive.com/dynamicindex1/omnislide/index.htm) JS routine for a navbar. Tested and works with IE7, Firefox, Opera and Safari but renders poorly with IE 6 and likely earlier IEs. And doesn't render at all with IE running on a Mac. Therefore I'm using this site's Browser Sniffer (http://www.dynamicdrive.com/dynamicindex9/browsersniffer.htm) JS routine to identify both platform and IE versions and then switch the user to an advisory notice.

I've placed the JS Browser Sniffer routine and test in the header and have tried your above code at the end of the Sniffer. Also tried moving the Sniffer and test into the body. Have tried simplifying the code to just test for the Mac platform and put up an alert. They all fail.

Here's the test site (http://www.morleychalmers.com/MostlyTheravada/mtindex.html). And here's the JS code I'm using.


<script type="text/javascript">

//CS1.1

var exclude=1;
var agt=navigator.userAgent.toLowerCase();
var win=0;var mac=0;var lin=1;
if(agt.indexOf('win')!=-1){win=1;lin=0;}
if(agt.indexOf('mac')!=-1){mac=1;lin=0;}
var lnx=0;if(lin){lnx=1;}
var ice=0;
var ie=0;var ie4=0;var ie5=0;var ie6=0;var com=0;var dcm;
var op5=0;var op6=0;var op7=0;
var ns4=0;var ns6=0;var ns7=0;var mz7=0;var kde=0;var saf=0;
if(typeof navigator.vendor!="undefined" && navigator.vendor=="KDE"){
var thisKDE=agt;
var splitKDE=thisKDE.split("konqueror/");
var aKDE=splitKDE[1].split("; ");
var KDEn=parseFloat(aKDE[0]);
if(KDEn>=2.2){
kde=1;
ns6=1;
exclude=0;
}
}
else if(agt.indexOf('webtv')!=-1){exclude=1;}
else if(typeof window.opera!="undefined"){
exclude=0;
if(/opera[\/ ][5]/.test(agt)){op5=1;}
if(/opera[\/ ][6]/.test(agt)){op6=1;}
if(/opera[\/ ][7-9]/.test(agt)){op7=1;}
}
else if(typeof document.all!="undefined"&&!kde){
exclude=0;
ie=1;
if(typeof document.getElementById!="undefined"){
ie5=1;
if(agt.indexOf("msie 6")!=-1){
ie6=1;
dcm=document.compatMode;
if(dcm!="BackCompat"){com=1;}
}
}
else{ie4=1;}
}
else if(typeof document.getElementById!="undefined"){
exclude=0;
if(agt.indexOf("netscape/6")!=-1||agt.indexOf("netscape6")!=-1){ns6=1;}
else if(agt.indexOf("netscape/7")!=-1||agt.indexOf("netscape7")!=-1){ns6=1;ns7=1;}
else if(agt.indexOf("gecko")!=-1){ns6=1;mz7=1;}
if(agt.indexOf("safari")!=-1 || (typeof document.childNodes!="undefined" && typeof document.all=="undefined" && typeof navigator.taintEnabled=="undefined")){mz7=0;ns6=1;saf=1;}
}
else if((agt.indexOf('mozilla')!=-1)&&(parseInt(navigator.appVersion)>=4)){
exclude=0;
ns4=1;
if(typeof navigator.mimeTypes['*']=="undefined"){
exclude=1;
ns4=0;
}
}
if(agt.indexOf('escape')!=-1){exclude=1;ns4=0;}
if(typeof navigator.__ice_version!="undefined"){exclude=1;ie4=0;}

/* Switch to warning page if IE is being used on a Mac */
if(mac=1 + ie=1){window.location = "http://www.morleychalmers.com/MostlyTheravada/ieMacPage.html";}

/* Switch to warning page if IE4, 5 or 6 is being used on a PC */
if(win=1 + (ie4=1 | ie5=1 | ie6=1)){window.location = "http://www.morleychalmers.com/MostlyTheravada/iePCPage.html";}
</script>

What am I missing? Appreciated.

Jas
03-09-2008, 06:50 PM
Sorry, I've looked a couple of times but cannot find the problem with the script. I couldn't even get the script to run :( Hopefully someone else will come along and figure it out. If not, maybe when I can get some time I can try coding it from scratch for you-- but I doubt I'll find the time for that. I suggest finding a different version of the script and starting over.

wanapitei
03-10-2008, 03:07 PM
Sorry, I've looked a couple of times but cannot find the problem with the script. I couldn't even get the script to run :( Hopefully someone else will come along and figure it out. If not, maybe when I can get some time I can try coding it from scratch for you-- but I doubt I'll find the time for that. I suggest finding a different version of the script and starting over.

Appreciate at least your report that the code appears to be well structured, that there's no obvious errors hanging out.

Now that Microsoft has embraced standards rather than continuing to attempt to force everyone else to adopt their standards (I've seen reports that IE8 now in beta goes even further into conforming) I'm not at all embarrassed to prompt users to upgrade to the browser of their choice in order to view my site.

After silence on this thread for a few days I posted an almost identical thread on the Dynamic Drive Scripts Help forum located here (ttp://www.dynamicdrive.com/forums/showthread.php?p=134137#post134137). No one has picked up on it there as yet.

I really appreciate the help I've received on this site, both in downloadedable routines and the answering of questions. I wish I had more skills to offer to give back. This is clearly one of the best tech assistance sites I've ever found.

Kind regards,