PDA

View Full Version : Help with detecting browser version code


DiaH
09-24-2002, 07:36 PM
I found this line of code in a freebie javascript that detects the CORRECT (yipee!) version of the browser when using IE.

navigator.appVersion.substring(navigator.appVersion.indexOf("MSIE ")+5,navigator.appVersion.indexOf("MSIE ")+8)

It does not come up with anything useable when the browser is Netscape. I tried changing "MSIE" to "Netscape" but it didn't work.

Anyone know how to tweak this to work with Netscape?? I am not so concerned about IE versions but really really really have to limit access by those with Netscape 4.7.

Thanks,
Dia

Catman
09-24-2002, 07:48 PM
I've found this seems to work for singling out NS4.7:


br = "other";
bName=navigator.appName;
bVer=parseInt(navigator.appVersion);
if (bName == "Netscape" && bVer >=5) br ="n6";
else if (bName == "Netscape" && bVer >=0) br ="n4";

DiaH
09-24-2002, 08:21 PM
Thanks for that bit of help.

Here's a part II question for you.

When the browser is loading the page to the point where it detects the version, how do I get it to not really show the page first. For example, the index page starts to load and as soon as its done (about a second or 2) it redirects to the designated page. I really would like to not show them the initial page unless they have the right version browser.

Thanks,
Dia

jamescover
09-25-2002, 01:01 AM
To detect NN4.7, I just use:

if (document.layers) {
do something;//your code goes here
}

So, in your case you can just launch a new window:if

if (document.layers) {
window.open('fileName.html','winName','width=100,height=100');
}

or, fill the same window:


if (document.layers) {
window.location.href="fileName.html";//your NN4.7 page goes here
}



James
He is risen!!!

Skyzyx
09-25-2002, 07:25 AM
Well, if you want to detect just about anything, I've written a JavaScript library with several commands that allow much flexibility.

Download the library from http://skyzyx.freehomepage.com/api/kernal.js

With this, you can detect just about any browser stuff, as well as a bunch of other stuff. For Example:


if (browser.ie5)
{
// Instructions for Internet Explorer 5.x (5.0, 5.01, 5.5)
}
else if (browser.ie6)
{
// Instructions for Internet Explorer 6.x (6.0)
}
else if (browser.ie5up)
{
// Instructions for Internet Explorer 5.0 or newer
}
else if (browser.netscape4)
{
// Instructions for Netscape 4.x (4.0, 4.03, 4.04, 4.05, 4.5, 4.6, 4.7, 4.8, etc...)
}
if (browser.netscape6)
{
// Instructions for Netscape 6.x (6.0, 6.01, 6.1, 6.2, 6.2.3, etc...)
}
else if (browser.netscape)
{
// Instructions for any Netscape browser.
}
else if (browser.mozilla)
{
// Instructions for any Mozilla Build.
}
else if (browser.gecko)
{
// Instructions for any Gecko-based browser (Netscape 6/7, Mozilla, Chimera, CompuServe 7.0, AOL 8.0 Beta, AOL 7.0 for MacOSX, etc...)
}
else alert(browser.version); // Will alert the browser's name and full version (i.e. Internet Explorer 6.0, Netscape 6.2.3, Mozilla 1.2a, etc.)


There are many, many, many more commands if you look through the source. You can also detect Operating Systems, Screen Resolution, CPU, JavaScript version supported, and various plug-ins.