How to redirect visitors to different pages depending upon their browser using  java script. Is it possible? Yes, it’s possible. Here is the code,



<script type=”text/javascript”>
<!–
var bname = navigator.appName;
if (bname.search(/netscape/i) == 0)
{
window.location=”netscape.html”;
}
else if (bname.search(/microsoft/i) == 0)
{
window.location=”internetexplorer.html”;
}
else
{
window.location=”other_browsers.html”;
}
//–>
</script>

After assigning the browser name to bname, we search for the presence of specific words using JavaScript Regular Expressions. (JavaScript Regular expressions have been included in version 1.2 of the language and are based on those found in the Perl language. So if you were familiar with Perl, picking up the JavaScript regular expressions would be very simple).

The search() method searches for the string specified between the two forward slashes “/”. The ‘i’ modifier makes it possible for case sensitive searches.

The JavaScript If tests whether condition is true or false. Thus, Netscape users are redirected to netscape.html, Internet Explorer users to internetexplorer.html and other browsers to “other_browsers.html”. The above code has to be placed inside the HTML head. It can also be contained inside a function which can be called using the onload().