![]() |
|
Browser Specific codeSince the different browsers does not support the same features and does not show html-pages in the same way, you may want to specify different code for some browsers. There are many different ways to do this. I have tested the following browsers:
LanguagesThe different browsers support different languages. You can use this to hide entire scripts. You can get extra code in certain browsers by using the example below. Values for Some Language are:
<script language="Some Language">
<!--
document.write("Language Dependent code here")
-->
</script>
JavaScript / document.writeThis script gives different code for Microsoft Internet Explorer 3+, Netscape Navigator 2+, Opera 3+ and other browsers.
<script language=javascript type="text/javascript">
<!--
if(navigator.userAgent.substring(0,8) == "Mozilla/")
if (navigator.userAgent.indexOf("MSIE") == -1)
if (navigator.userAgent.indexOf("Opera") == -1)
document.writeln("Netscape Navigator code here")
else
document.writeln("Opera code here")
else
document.writeln("Microsoft Internet Explorer code here")
else
document.writeln("Other Javascript enabled browser code here")
// -->
</script>
<noscript>
Other browser / javascript disabled browser code here.
</noscript>
Note: Early versions of Netscape Navigator 3, have problems using the script within tables. It also writes the script code. A solution to this problem is to put a <font color="..."> ... </font> around your script. The ... color is a color that is nearly invisible when written on the wallpaper/background color. If you use the script to write messages on the screen instead of code, also put a <font color="..."> ... </font> around the message. The ... color is here the same as the textcolor. Also, version 2 of Netscape Navigator does not support <noscript>. The Other browser code / javascript disabled will also be written after the Netscape Navigator code for this browser. This script gives different code for Microsoft Internet Explorer 3,4, Netscape Navigator 2,3,4 and other browsers / javascript disabled. The note above also applies to this script.
<script language=javascript type="text/javascript">
<!--
if(navigator.userAgent.indexOf("MSIE 3.0") != -1)
document.writeln("Microsoft Internet Explorer 3 code here")
else if(navigator.userAgent.indexOf("MSIE 4.0") != -1)
document.writeln("Microsoft Internet Explorer 4 code here")
else if(navigator.userAgent.indexOf("Opera/3") != -1)
document.writeln("Opera 3 code here")
else if(navigator.userAgent.substring(0,11) == "Mozilla/2.0")
document.writeln("Netscape Navigator 2 code here")
else if(navigator.userAgent.substring(0,11) == "Mozilla/3.0")
document.writeln("Netscape Navigator 3 code here")
else if(navigator.userAgent.substring(0,11) == "Mozilla/4.0")
document.writeln("Netscape Navigator 4 code here")
// -->
</script>
<noscript>
Other browser / javascript disabled code here
</noscript>
Instead of evaluating navigator.userAgent you can also evaluate parseInt( navigator.appVersion ) >= n. You can catch some very special browsers this way:
Load a different document for each browserYou can modify the scripts above to load separate documents for different browsers. Instead of using document.write(), you can use:
Both loads a new document in the browser. If you make a script-document that immediately loads a browser dependent page, you should use location.replace when possible. It replaces the history-entry of the script-document and insures that the browsers back/forward buttons work correctly. Browser Dependent LinksThe code below gets different documents different browsers.
<a href="default url" OnClick="return CheckBrowser()">MyLink</a>
<script language=javascript type="text/javascript">
<!--
function CheckBrowser()
{ if (certain browser check)
{ location.href = "certain browser url";
return false;
}
location.href = "default url";
return true;
}
// -->
</script>
Related articles: |
welcome |
cartoons |
jokes |
daily jokes |
sitemap |
search |
feedback |
what's new Copyright © 1997-2007 Real Comedy Inc.
|