Wednesday, December 21, 2011

How to deliver browser specific content using JavaScript

If you have a need to deliver browser specific web pages and if you don't have a server-side script to do this with, take a look at the following HTML/JavaScript code:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
  if( -1 != navigator.userAgent.
      indexOf ("AOL") )
  {
    // load America Online version
    location.href="aol.htm";
  }
  else
  if( -1 != navigator.userAgent.
      indexOf ("MSIE") )
  {
    // load Microsoft Internet 
    // Explorer version
    location.href="msie.htm";
  }
  else
  if( -1 != navigator.userAgent.
      indexOf ("Mozilla") )
  {
    // load Netscape version
    location.href="netscape.htm";
  }
  else
  {
    // load other version
    location.href="other.htm";
  }
-->
</SCRIPT>
You can simply plug in above tags after replacing "netscape.htm" with the URL to your Netscape specific page, "other.htm" with your generic page's URL, "MSIE.htm" with the Microsoft Internet Explorer version of the page, etc.

0 comments:

Post a Comment

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Best Web Hosting