Browser Detection

Main Page | Session 11 Index | if-else Construct & Condition Statements


Browser detection can be performed using the Navigator object and JavaScript, combined with the refresh META tag option.

The following code in the HEAD section of a web page is required for browser detection and redirection to specific web pages.

<!-- ARCHIVE by FORTUNECITY.ws --> <HEAD> <META HTTP-EQUIV="REFRESH" CONTENT="6;URL=index1.html"> <SCRIPT LANGUAGE="JavaScript"> <!-- var name = navigator.appName; var agent = navigator.userAgent; timerID=setTimeout("checkBrowser()",5000); function checkBrowser() { if (name == "Microsoft Internet Explorer") { if (agent.indexOf ("MSIE 3") != -1) self.location.href="ie3.html"; else if (agent.indexOf ("MSIE 4") != -1) self.location.href="ie4.html"; else if (agent.indexOf ("MSIE 5") != -1) self.location.href="ie5.html"; } else { if (name == "Netscape") { if (agent.indexOf ("Mozilla/4") != -1) self.location.href="communicator.html"; else if (agent.indexOf ("Mozilla/3") != -1) self.location.href = (agent.indexOf ("16bit") != -1) ? "./nav316.html" : "./nav332.html"; } } } // --> </SCRIPT> </HEAD>

Click here to check your browser type.


Main Page | Session 11 Index | if-else Construct & Condition Statements