SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Reliable Javascript version detection?

    I have been struggling around with trying to figure out a reliable manner for detecting the Javascript version a given browser is using.

    Basically, there are two half-decent ways that I have found, neither one being foolproof.

    One way is using javascript tags with the language attribute, as in the following code:

    Code:
    <SCRIPT LANGUAGE="Javascript"><!--
    gVersion="1.0";
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="Javascript1.1"><!--
    gVersion="1.1";
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="Javascript1.2"><!--
    gVersion="1.2";
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="Javascript1.3"><!--
    gVersion="1.3";
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="Javascript1.4"><!--
    gVersion="1.4";
    //-->
    </SCRIPT>
    <SCRIPT LANGUAGE="Javascript1.5"><!--
    gVersion="1.5";
    //-->
    </SCRIPT>


    This works fine but it is not very elegant. Another disadvantage is that it is not XHTML compliant.

    The other way is using some sniffer scripting like that found in the JavaScript Browser Sniffer (Web Reference).

    However, this is not very reliable as it needs to be constantly updated to take newer browsers into consideration. Also, on my system it gave an incorrect Javasctipt version of 1.3 when it should have given 1.5 (according to the first option above).

    I was just wondering if there was a more dependable way of doing this.

    Maybe it would just be better to avoid unnecessary headaches and restrict myself to W3C compliant brwosers.

    Or not?
    Kiffin
    Your average future-famous kind of guy...

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Knowing the javascript verion really doesn't help much. I can think of maybe only 1 or 2 times when version detection is better than object detection.

    My advice? Don't worry about the version - just test for object/property support when you need it.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I think you are right. However, for curiosity's sake I was just wondering if it would be possible to get the javascript version, e.g. for a web-enabled analysis tool I am working on. Thanks in advance.
    Kiffin
    Your average future-famous kind of guy...

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see. Well, the two methods you've mentioned are the only ones I'm familiar with. Besides - finding the Javascript version is a theoretical figure at best - IE doesn't even actually use JavaScript - it uses JScript - their own ECMAscript implementation.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have to agree with beetle. Indeed, I can see no reason why JavaScript version detection would be of any practical use in the face of Object-Detection and, although less favorable, Browser-Detection.
    Of course, that's just my opinion. I could be wrong.

  6. #6
    SitePoint Enthusiast kgish's Avatar
    Join Date
    Dec 2001
    Location
    Gouda, The Netherlands
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, you guys and/or experts have made your points and in the end I am convinced. Javascript version detection has been officially dropped from my future famous analysis tool.

    In place of that I can do object detection, say for things like document.all, document.images, layers and that kind of thing.

    Thanks again.
    Kiffin
    Your average future-famous kind of guy...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •