code by lostinbeta  & explanation by kirupa

There are times when you would want a page to display in only a certain browser. To achieve that, you can use a browser re-direction script that detects and re-directs a visitor to a customized page depending on the browser your visitor is using.

The Code:

[ copy the above code into a detection page ]

In your HTML page that you want to have your script, copy and paste the above code. When you save and preview the page in your browser, you will not see anything happening just yet. You will need customize it a little bit though.

When Page Is Entered
If you want the browser to be detected immediately once the page has been entered, add the following line to the end of your code:


The above method is probably the most popular, and more than likely, you will be using the above method in your site. A few other methods and customizations are mentioned below:

Detect on Click
You can also have the browser detection script work only when a user clicks on a link. For such a scenario, use the following line of code in your HTML document where you want the link to be displayed:

<A HREF="javascript:checkBrowser()">Click to Check Browser</A>

Of course, if you observed the code, you will need to create individual pages for each of the browsers with the names specified such as ie.html, opera.html, oldns.html, and newns.html. You can save some time by simply creating one html page for alternate browsers and tell them all to go to that page instead:

[ just a minor modification to the above script ]

No-Redirect for IE
If you are fairly savvy with JavaScript and are familiar with a lot of the features, you can customize the script to your full liking. For example, let us take Internet Explorer as our target browser. If you want everybody who is using Internet Explorer to stay on the current page instead of being re-directed to a different page like ie.html, simply delete the following lines from the code:

  else if (IE) {
    window.location = "ie.html";

Experiment and try new things with this script! I hope this information helped. If you have any questions or comments, please don't hesitate to post them on the forums found by clicking here.



SUPPORTERS:'s fast and reliable hosting provided by Media Temple.