Welcome to Jokes2000. Tips for improving your website: Graphic, HTML and javascript A fine collection of cartoons Jokes jokes jokes - get a good laugh Joke of the day and mailing list Table of contents
Jokes2000.com Jokes2000.com
 

Browser Specific code 

Since 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:

  • Netscape Navigator (all major versions)
  • Microsoft Internet Explorer (all major versions)
  • Opera 3.0

Languages

The 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:

Value Supporting Browsers
JavaScript Netscape Navigator 2+, Microsoft Internet Explorer 3+, Opera 3.0
JavaScript1.1   Netscape Navigator 3+, Microsoft Internet Explorer 4+
JavaScript1.2 Netscape Navigator 4+, Microsoft Internet Explorer 4+
VBScript Microsoft Internet Explorer 3+
JScript Microsoft Internet Explorer 4+

<script language="Some Language">
<!--
  document.write("Language Dependent code here")
-->
</script>


JavaScript / document.write

This 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:

n   Browsers
2 Netscape Navigator 2 / Microsoft Internet Explorer 3
3 Netscape Navigator 3 / Microsoft Internet Explorer 3.01 for Macintosh / Opera 3.0
4 Netscape Navigator 4 / Microsoft Internet Explorer 4


Load a different document for each browser

You can modify the scripts above to load separate documents for different browsers. Instead of using document.write(), you can use:

  • location.replace("some url") not supported by Netscape Navigator 2
  • location.href = "some url"

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 Links

The 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:
Hide StyleSheet
Technical Analysis of Browsers


Affiliate Sites: Funny Videos | Fight Videos | Free Arcade Games


welcome | cartoons | jokes | daily jokes | sitemap | search | feedback | what's new

Copyright © 1997-2007 Real Comedy Inc.