Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i am looking for a code that can check the browser and version of a visitor.
Based on the outcome it should direct it to the HTML5 supported website otherwise the code needs to direct the user to annon compliant website.

This is my code, but it's not working:

XML
<html>
  <head>
  <title>Browser detection</Title>
  <Script Language="JavaScript">
  // Detect the browsername
    browsername=navigator.appName;
    if (browsername.indexOf("Netscape")!=-1) {browsername="NS"}
    else
    {
      if (browsername.indexOf("Microsoft")!=-1) {browsername="MSIE"}
      else {browsername="N/A"}
    };

    //detect the browserversion
    browserversion="0";
    if (navigator.appVersion.indexOf("2.")!=-1) {browserversion="2"};
    if (navigator.appVersion.indexOf("3.")!=-1) {browserversion="3"};
    if (navigator.appVersion.indexOf("4.")!=-1) {browserversion="4"};
    if (navigator.appVersion.indexOf("5.")!=-1) {browserversion="5"};
    if (navigator.appVersion.indexOf("6.")!=-1) {browserversion="6"};

    // Send visitor to relevant pages
    if (browsername=="NS") {window.location="http://www.yahoo.com"};
    if (browsername=="MSIE"){
      if (browserversion<4){window.location="http://www.hotbot.com"}
      else {window.location="http://www.msn.com"}
    }
    if (browsername=="N/A") {window.location="http://www.webcrawler.com"};
  </script>
  </head>
  <body>
  </body>
</html>


Thanks a lot!
filip
Posted
Updated 13-Mar-13 4:37am
v2
Comments
joshrduncan2012 13-Mar-13 10:20am    
This isn't a question. Are you wanting someone to write the code for you? I doubt anyone will do that for you here.

it works now.

XML
<html>
<head>
<title>Browser detection</Title>
<Script Language="JavaScript">
// Detect the browsername
browsername=navigator.appName;
if (browsername.indexOf("Netscape")!=-1) {browsername="NS"}
else
{if (browsername.indexOf("Microsoft")!=-1) {browsername="MSIE"}
else {browsername="N/A"}};

//detect the browserversion
browserversion="0";
if (navigator.appVersion.indexOf("2.")!=-1) {browserversion="2"};
if (navigator.appVersion.indexOf("3.")!=-1) {browserversion="3"};
if (navigator.appVersion.indexOf("4.")!=-1) {browserversion="4"};
if (navigator.appVersion.indexOf("5.")!=-1) {browserversion="5"};
if (navigator.appVersion.indexOf("6.")!=-1) {browserversion="6"};

// Send visitor to relevant pages
if (browsername=="NS") {window.location="http://www.yahoo.com"};
if (browsername=="MSIE"){
  if (browserversion<4){window.location="http://www.hotbot.com"}
  else {window.location="http://www.msn.com"}
}
if (browsername=="N/A") {window.location="http://www.webcrawler.com"};
</script>
</head>

<body>
</body>
</html>
 
Share this answer
 
Use modernizr[^] instead.
Quote:
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900