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: ... |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Member Join Date: Jan 2009 Location: Kent, UK
Posts: 113
Blog Entries: 11 Thanks: 0
Thanked 1 Time in 1 Post
![]() Expertise: (X)HTML / CSS Experience: Quite Good |
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>
__________________ Boris Johnson for future PM! |
| |
| | #2 |
| Member Join Date: Jan 2009 Location: Kent, UK
Posts: 113
Blog Entries: 11 Thanks: 0
Thanked 1 Time in 1 Post
![]() Expertise: (X)HTML / CSS Experience: Quite Good |
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 |
| |
![]() |
| Tags |
| browser, detection, trouble |
| Thread Tools | |
| Display Modes | |