...

View Full Version : Use different .js files based on browser type?



surfsup
07-10-2002, 03:16 PM
How can I use different .js files based on the browser type? The below code does not work, please help.

Thanks William.

<script language="JavaScript1.2">
if (document.layers) { // NetScape 4.x
src="netscape4x_menu.js"
}
else { // IE or NetScape 6/Mozilla
src="non_netscape4x_menu.js"
}
</script>

tamienne
07-10-2002, 03:31 PM
<script language="JavaScript1.2">
if (document.layers) { // NetScape 4.x

document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

} else { // IE or NetScape 6/Mozilla
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='non_netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

}
</script>

requestcode
07-10-2002, 03:33 PM
I don't beleive you can do that. Why don't you combine both scripts into one exteranal file?

I stand corrected. I tested it and you can, but I still wonder why you don't combine the two scripts.

surfsup
07-11-2002, 02:22 PM
I copied and pasted the code from Tamienne into
the <head> of a page and I receive javascript
error messages.

Thanks William.

JohnKrutsch
07-11-2002, 03:18 PM
Make sure you don't have line breaks in there:



<script language="JavaScript1.2">
if (document.layers) { // NetScape 4.x

document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

} else { // IE or NetScape 6/Mozilla
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='non_netscape4x_menu.js' TYPE='text/javascript'><\/SCRIPT>");

}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum