PDA

View Full Version : Change script depending on browser



mark200
04-25-2006, 05:42 PM
Ok, I'm gettin a bit annoyed with all the hassle I'm going through the get a good navagation bar that is cross browser. I was wondering if there is someway to change a navagation bar depending on the broswer the viewer is using. I don't want the whole page to change as this would use up a lot of hosting space, i just want the script that is loaded to be different. I'd like something like one script for IE, and another for any other browser.
This would just make the viewing of the site a lot more pleasent, but no worries if this isn't possible.
Thanks,
Mark

Twey
04-25-2006, 05:59 PM
This is very easy.
if(document.all) {
// IE code
} else {
// other code
}However, don't use browser detection too often. It's an ugly hack, and as such only suitable for compensating for other bugs -- and even then not when there is an alternative.

mark200
04-25-2006, 06:07 PM
Thanks. How do I write it so I can give the sources of the two scripts. And i put
<script language="JavaScript" type="text/javascript"> before it?

Also, is it possible to have two scripts to load for the none-IE one.

mwinter
04-25-2006, 06:08 PM
This is very easy.
if(document.all) {
// IE code
} else {
// other code
}That doesn't work at all. See a relevant Usenet post (http://groups.google.co.uk/group/comp.lang.javascript/msg/a64d489104046c6f) by Richard Cornford.

Browser detection doesn't work. How many times does that need to be said?

Mike