943,935 Members | Top Members by Rank

Ad:
May 29th, 2007
0

Hmm... Javascript error, or Mozilla stupidity?

Expand Post »
I wrote this simple code to return my browser's name, because I've never tested this in Firefox:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <html> <body>
  2. <script type="text/javascript">
  3. var browser=navigator.appName
  4. var b_version=navigator.appVersion
  5. var version=parseFloat(b_version) document.write("Browser: "+ browser)
  6. document.write("<br>")
  7. document.write("Version: "+ version)
  8. </script>
  9. </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*
Attached Thumbnails
Click image for larger version

Name:	fferror.png
Views:	51
Size:	70.1 KB
ID:	3526  
Last edited by linux; May 29th, 2007 at 9:40 pm.
Similar Threads
Reputation Points: 118
Solved Threads: 30
Posting Shark
linux is offline Offline
931 posts
since Aug 2006
May 29th, 2007
1

Re: Hmm... Javascript error, or Mozilla stupidity?

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

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. (ignore my semicolons if you don't use 'em)
  2. <html> <body>
  3. <script type="text/javascript">
  4. var u_agent=navigator.userAgent;
  5. var browser=navigator.appName;
  6. var b_version=navigator.appVersion;
  7. var version=parseFloat(b_version);
  8. document.write("UserAgent: "+ u_agent);
  9. document.write("<br>");
  10. document.write("Browser: "+ browser);
  11. document.write("<br>");
  12. document.write("Version: "+ version);
  13. </script>
  14. </body> </html>
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
May 30th, 2007
0

Re: Hmm... Javascript error, or Mozilla stupidity?

Thanks, it helps a lot.
Reputation Points: 118
Solved Threads: 30
Posting Shark
linux is offline Offline
931 posts
since Aug 2006
Jun 1st, 2007
0

Re: Hmm... Javascript error, or Mozilla stupidity?

Very interesting!!!!!!

I tried the 2nd script written by MattEvans and it said i have IE4!!
Quote ...
Browser: Microsoft Internet Explorer
Version: 4
I have 6

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 6:35 pm.
Reputation Points: 1054
Solved Threads: 28
Nearly a Senior Poster
The Dude is offline Offline
3,425 posts
since Dec 2005
Jun 1st, 2007
0

Re: Hmm... Javascript error, or Mozilla stupidity?

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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; X11; Linux i686; en)
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var version=parseFloat(b_version) document.write("Browser: "+ browser)
Should be on two lines:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var version=parseFloat(b_version)
  2. document.write("Browser: "+ browser)
((A problem that's easily solved forever by not ommiting the optional semicolon after each line!!))
Last edited by MattEvans; Jun 1st, 2007 at 9:41 pm.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Page Cannot Be Displayed - javascript:doNetDetect()
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: javascript function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC