Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional inclusion of a script depending on browser

Status
Not open for further replies.

Knackers

Technical User
Apr 26, 2001
59
0
0
AU
I have a JavaScript menu that is appearing differently in Explorer and Netscape (the obsolute positioning is different). To solve this, I figured I would just have a Microsoft and Netscape version of the script, and have some kind of conditional inclusion...Does anyone know how?

Code:
if Explorer{
   <SCRIPT language=JavaScript src=&quot;explorermenu.js&quot; type=text/javascript></SCRIPT>
}

if Netscape{
   <SCRIPT language=JavaScript src=&quot;netscapemenu.js&quot; type=text/javascript></SCRIPT>
}
Cheers
 
hi Knackers,

this type of branching is typically handled in your code, like:
[tt]
var isIE = navigator.appName.toLowerCase().indexOf(&quot;microsoft&quot;) > -1;

if (isIE) {
// do this...
} else {
// do that...
}
[/tt]

if you really want to write separate code/pages, you could simply use a redirect after a browser check:
[tt]
if (document.all) {
// ie
window.location.href = &quot;myIEPage.html&quot;;
}
else {
// other than ie
window.location.href = &quot;myNSPage.html&quot;;
}
[/tt]

please note that my browser check above is crude...google for &quot;javascript browser detect&quot; for some sophisticated script.



=========================================================
if (!succeed) try();
-jeff
 
Thanks Jeff

I din't really want to have seperate site for different browsers. The site this is for is written in PHP, so I have used some of the built in functions to handle browser checking on the server side and all is working.

Thanks for your quick post though!

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top