Click to See Complete Forum and Search --> : Else If Browser


lukezweb
11-20-2003, 10:04 AM
Does anyone have or could quickly make a small code that does this:

Detects if browser is IE {
AREA WHERE I CAN ADD A SCRIPT
} ELSE IF (
If browser is netscape
AREA WHERE I CAN ADD A SCRIPT
} ELSE IF {
If Browser Is Mozilla
AREA I CAN ADD A CODE
} ELSE {
document.write("Your Browser Is Not Either Netscape, IE or Mozilla, these are the main browsers that Web coders code for please buy one or download a free version soon. The coding here will not work for you!")
}

Thanks

gil davis
11-20-2003, 10:25 AM
Please take this as constructive criticism.

First of all, you should not make a blanket statement about what other web coders do.

Second of all, you should not try to dictate what browser a person should use or purchase.

Third of all, you should learn to code in such a way that if someone uses a browser that you did not plan for, it should fail gracefully.

If you want to see a comprehensive browser detection script, see http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html . Another good reference is http://www.mozilla.org/catalog/web-developer/

gil davis
11-20-2003, 10:31 AM
Versions of IE can be detected using document.all (except Opera also supports it).

Netscape 4 can be detected using document.layers.

Versions of DOM-complaint browsers (the ones you really should be coding for) can be detected using document.getElementById.


if (document.getElementById)
{
// code for W3 DOM compliant browsers
// Mozilla, NS 6+, IE 5+
}
else
{if (document.layers)
{
// code for NS 4
}
else
{if (document.all)
{
// code for IE 4
}
}
}