Click to See Complete Forum and Search --> : Checking for browser - IE & Netscape


Fly_Moe
10-22-2003, 02:06 PM
The site I'm developing is only going to be coded for IE 5.0+ and Netscape 7.0+. Now, the problem that I'm having is when I check in Netscape 6.01, the browserversion that comes back is 5.0. I don't know why. It's weird. Anyone see something in my code that you see wrong? Or is it a Netscape error? Anyone have any suggestions on how to fix it?

Here's the code that I used to check for the browser and version :



<Script Language="JavaScript">
// detect the browsername
browsername=navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {browsername="NS"}
else
{if (browsername.indexOf("Microsoft")!=-1) {browsername="MSIE"}
else {browsername="N/A"}};

//detect the browserversion
browserversion="0";
if (navigator.appVersion.indexOf("2.")!=-1) {browserversion="2"};
if (navigator.appVersion.indexOf("3.")!=-1) {browserversion="3"};
if (navigator.appVersion.indexOf("4.")!=-1) {browserversion="4"};
if (navigator.appVersion.indexOf("5.")!=-1) {browserversion="5"};
if (navigator.appVersion.indexOf("6.")!=-1) {browserversion="6"};
if (navigator.appVersion.indexOf("7.")!=-1) {browserversion="7"};

// Send visitor to relevant pages
if (browsername=="MSIE"){
if (browserversion>=5){
// This is where the redirection will happen
document.write("Testing MSIE")
}};
if (browsername=="NS"){
if (browserversion==7){
// This is where the redirection happens
document.write("Testing NS")
}};
document.write("NA You are using an unsupported browser")
</script>

Jona
10-22-2003, 02:12 PM
First of all, I suggest that you make all of your sites valid (X)HTML (http://validator.w3.org/) and valid CSS (http://jigsaw.w3.org/css-validator/), and that it works for all browsers.


var browser = navigator.appName;
var bVer = parseInt(navigator.appVersion);
if(browser == "Netscape" && bVer < 5) {
&nbsp; document.write("You are using Netscape version 5 or earlier.");
}
if(browser == "Netscape" && bVer > 5) {
&nbsp; document.write("You are using Netscape version 6 or later.");
}
if(browser == "Microsoft Internet Explorer" && bVer < 5) {
&nbsp; document.write("You are using MSIE version 5 or earlier.");
} else if(browser == "Microsoft Internet Explorer" && bVer > 5){
&nbsp; &nbsp;document.write("You are using MSIE version 6 or greater.");
}


[J]ona

Fly_Moe
10-22-2003, 02:35 PM
I guess I didn't state the problem well enough. To clarify what I was trying to get accross, when I write out navigator.appVersion in Netscape 6.01, I get 5.0 (Windows; en-US) . Obviously I'm not using version 5.0. Is this a Netscape issue or something else? Has anyone else run accross this? Or is Netscape actually 5.0 for 6, 4.0 for 5, 3.0 for 4, etc.....?

Jona
10-22-2003, 02:43 PM
In that case, use <= 5 instead of < 5... I just tested it in NS 6.0.2, and it returns five. I am not sure why, but you're making the site for version 7+, so six shouldn't be a problem...

[J]ona