Click to See Complete Forum and Search --> : javascript css linker and redirect


Anson
10-18-2003, 08:25 PM
Hey guys,
I'm about to upload a site that uses the following script to dish out stylesheets and redirect old browsers. I hacked a couple different scripts together, and think it works, but i dont have an old version of ie to test on.

Can anyone look this over for me and tell me how i can improve it?

Thanks in advance,

Anson

script follows:
-------------
<script type="text/javascript"><!--
var IE4 = (navigator.appVersion.indexOf("MSIE") > 0);
var Netscape = (navigator.appName == "Netscape");
if(Netscape) {
var NetscapeVer = parseFloat(navigator.appVersion);
}
var OPERA = navigator.userAgent.indexOf("Opera") > -1;
var SAFARI = navigator.userAgent.indexOf("Safari") > -1;
var OS;
if (navigator.appVersion.indexOf("Win") > 0) OS = "Windows";
if (navigator.appVersion.indexOf("Mac") > 0) {OS = "MacOS";}

switch (OS) {
case "Windows":
if (IE4 > 0) window.location="error.html";
if (NetscapeVer < 5) window.location="error.html";
if (NetscapeVer >= 5) window.location="error.html";
if (OPERA > 0) window.location="error.html";
break;
case "MacOS":
if (SAFARI > 0) window.location="error.html";
if (IE4 > 0) document.write ('<link href="../../css-test/10-15-03/macIE.css" rel="stylesheet" type="text/css">');
if (NetscapeVer < 5) window.location="error.html";
if (NetscapeVer >= 5) window.location="error.html";
if (OPERA > 0) window.location="error.html";

break;
}
//-->
</script>

PunkSktBrdr01
10-18-2003, 11:05 PM
Why do you need that whole switch part at the end? Why not just do:


if (IE4 > 0) {
document.write ('<link href="../../css-test/10-15-03/macIE.css" rel="stylesheet" type="text/css">');
}
else {
window.location="error.html";
}