•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,771 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,752 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1528 | Replies: 4
![]() |
I wrote this simple code to return my browser's name, because I've never tested this in Firefox:
In, Firefox, it returns "Netscape 5." I uploaded a screen shot.
Error?
*sorry for all the blacked out things in the screenshot. You can never be too careful*
<html> <body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version) document.write("Browser: "+ browser)
document.write("<br>")
document.write("Version: "+ version)
</script>
</body> </html>In, Firefox, it returns "Netscape 5." I uploaded a screen shot.
Error?
*sorry for all the blacked out things in the screenshot. You can never be too careful*
Last edited by linux : May 29th, 2007 at 8:40 pm.
Toshiba M115 ● 1.49 GB DDR-2 RAM ● 1.6 GHz Centrino Duo ● 80GB HDD ● Windows XP Media Center Edition
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 964
Reputation:
Rep Power: 5
Solved Threads: 48
Hm, I thought perhaps you might have wierd browser identification settings.. But apparently not; I tested that code in Firefox 2, and in Opera 9 ( which can pretend to be other browsers; and is pretending to be Mozilla today ). In both cases; Netscape 5 is given back, as per your example. I imagine that this is an attempt to indicate that Firefox and Netscape are compatible on some level...
The userAgent string is perhaps more useful; it's more difficult to use, because you have to parse it manually, or at least search for known indicators within it:
'Real' Firefox
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Opera Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en) Opera 9.02
Opera REALLY Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en; rv:1.7.5) Gecko/20041110
The userAgent string is perhaps more useful; it's more difficult to use, because you have to parse it manually, or at least search for known indicators within it:
'Real' Firefox
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
Opera Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en) Opera 9.02
Opera REALLY Faking Mozilla
Mozilla/5.0 (X11; Linux i686; U; en; rv:1.7.5) Gecko/20041110
(ignore my semicolons if you don't use 'em)
<html> <body>
<script type="text/javascript">
var u_agent=navigator.userAgent;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
document.write("UserAgent: "+ u_agent);
document.write("<br>");
document.write("Browser: "+ browser);
document.write("<br>");
document.write("Version: "+ version);
</script>
</body> </html> If it only works in Internet Explorer; it doesn't work.
Very interesting!!!!!!
I tried the 2nd script written by MattEvans and it said i have IE4!!
I have 6 
Anyway to definetly verify this??
The first script didnt do anything when i went to it (Linux's script)
I tried the 2nd script written by MattEvans and it said i have IE4!!
•
•
•
•
Browser: Microsoft Internet Explorer
Version: 4

Anyway to definetly verify this??
The first script didnt do anything when i went to it (Linux's script)
Last edited by The Dude : Jun 1st, 2007 at 5:35 pm.
•
•
Join Date: Jul 2006
Location: Deptford, London
Posts: 964
Reputation:
Rep Power: 5
Solved Threads: 48
Look at the full userAgent string. It's weird though; this is for Opera identifying as Internet Explorer. Internet Explorer 6.0 under Wine (Linux) says similar. I can't (be bothered to) go on 'real' MS Windows:
The 'Mozilla/4.0' part is totally misleading again; the only clue is the MSIE 6.0 part... Which, when compared with the other userAgent strings; doesn't even appear in the same relative position in the string as 'Firefox' or 'Opera' does... Weird indeed.
Using browser detection for anything more than trivial isn't a good idea; partly because it's clearly diffiicult to get a version and browser application that are correct. Even something as obviously neccessarily standard as this; isn't well standardized (userAgent, appName, version give conflicting information, the userAgent string isn't in a standard order etc ).
Another reason why it's bad; is because some users give deliberately incorrect browser identification. For example, one of the websites I have to log onto frequently uses a check like: "is browser netscape X or ie Y? come in; else? sorry! your browser version is out-of-date." - Not so; my browser just isn't one of those two. So I ask it to pretend that it is (by sending a different userAgent string and appName) and in I go; often leaving that identification 'incorrect' for a while after.
Finally; browser version doesn't specifically (or manageably) indicate support or lack of support for any aspect of Javascript... I suppose it could be useful in solving misrepresentations of CSS on different browsers; although, even there, there are CSS-only hacks to isolate FF/Opera (and they can be inverted back to isolate IE via ordered overwriting rules).
See this for a bit more info about 'object detection' instead of browser detection:
http://www.quirksmode.org/js/support.html
And this, if your certain, shows a more complete parser for the appname/useragent return:
http://www.quirksmode.org/js/detect.html
NOTE: First script from linux (the user =P) has probably a copy-paste + upload + parse error:
Should be on two lines:
((A problem that's easily solved forever by not ommiting the optional semicolon after each line!!))
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686; en)
Using browser detection for anything more than trivial isn't a good idea; partly because it's clearly diffiicult to get a version and browser application that are correct. Even something as obviously neccessarily standard as this; isn't well standardized (userAgent, appName, version give conflicting information, the userAgent string isn't in a standard order etc ).
Another reason why it's bad; is because some users give deliberately incorrect browser identification. For example, one of the websites I have to log onto frequently uses a check like: "is browser netscape X or ie Y? come in; else? sorry! your browser version is out-of-date." - Not so; my browser just isn't one of those two. So I ask it to pretend that it is (by sending a different userAgent string and appName) and in I go; often leaving that identification 'incorrect' for a while after.
Finally; browser version doesn't specifically (or manageably) indicate support or lack of support for any aspect of Javascript... I suppose it could be useful in solving misrepresentations of CSS on different browsers; although, even there, there are CSS-only hacks to isolate FF/Opera (and they can be inverted back to isolate IE via ordered overwriting rules).
See this for a bit more info about 'object detection' instead of browser detection:
http://www.quirksmode.org/js/support.html
And this, if your certain, shows a more complete parser for the appname/useragent return:
http://www.quirksmode.org/js/detect.html
NOTE: First script from linux (the user =P) has probably a copy-paste + upload + parse error:
var version=parseFloat(b_version) document.write("Browser: "+ browser)var version=parseFloat(b_version)
document.write("Browser: "+ browser) Last edited by MattEvans : Jun 1st, 2007 at 8:41 pm.
If it only works in Internet Explorer; it doesn't work.
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax algos asp browser browsers browsing developer development email eudora europe firefox fortitude gecko home hope html internet internet explorer javascript leak linux memory microsoft mozilla msdn networking news office open source patch penelope phishing satnav scams security site social software sql struggle stupidity thunderbird trial-and-error users victory vista web
- Error: Expected ')' (HTML and CSS)
- a weird Javascript error (JavaScript / DHTML / AJAX)
- Subshell Problem, syntax error...Help please! (Shell Scripting)
- getting an IE popup whenever anything is closed. (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Page Cannot Be Displayed - javascript:doNetDetect()
- Next Thread: How would I display somethign only if javascript is enabled?



Linear Mode