Browser Detection trouble

This is a discussion on Browser Detection trouble within the Javascript forums, part of the Development category; I've written a browser detector for an assignment i'm doing in college, and i'm sure i've written it wrong: Code: ...


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 2nd June 2009, 02:54 PM   #1
Member
 
A800's Avatar
 
Join Date: Jan 2009
Location: Kent, UK
Posts: 113
Blog Entries: 11
Thanks: 0
Thanked 1 Time in 1 Post
A800 is on a distinguished road
Expertise: (X)HTML / CSS
Experience: Quite Good
Thumbs down Browser Detection trouble

I've written a browser detector for an assignment i'm doing in college, and i'm sure i've written it wrong:

Code:
<script type="text/javascript">
if (/MSIE (\d+\.\d+) ;/ .test(navigator.UserAgent)) { //text for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
  if (ieversion>=8)
   alert("You're using IE8 or above")
  else if (ieversion>=7)
   alert("You're using IE7")
  else if (ieversion>=6)
   alert("You're using IE6")
  else if (ieversion>=5)
   alert("You're using IE5")
}
else
 alert("You are using a non-IE browser..")
</script>
It always comes up with the else alert, even when I tested it on IE. Any suggestions??
__________________
Boris Johnson for future PM!
A800 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Old 4th June 2009, 08:07 AM   #2
Member
 
A800's Avatar
 
Join Date: Jan 2009
Location: Kent, UK
Posts: 113
Blog Entries: 11
Thanks: 0
Thanked 1 Time in 1 Post
A800 is on a distinguished road
Expertise: (X)HTML / CSS
Experience: Quite Good
Default

Figured what I wrote wrong, and I re-wrote it to this:

Code:
<SCRIPT language="JavaScript">
<!--
var browserName=navigator.appName; 
if (browserName=="Netscape")
{ 
 alert("You're using Netscape as your browser!");
}
else 
{ 
 if (browserName=="Microsoft Internet Explorer")
 {
  alert("You are using Internet Explorer!")
 }
 else
  {
    alert("You are using a different browser :)");
   }
}
//-->
</SCRIPT>
__________________
Boris Johnson for future PM!

Last edited by A800; 4th June 2009 at 08:13 AM.. Reason: corrected my mistake
A800 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Closed Thread

Tags
browser, detection, trouble

Thread Tools
Display Modes