To tell Javascript version of your browser

前端 未结 4 658
刺人心
刺人心 2020-12-21 22:02

I have the following script from http://javascript.about.com/library/bljver.htm


<         


        
相关标签:
4条回答
  • 2020-12-21 22:27

    Javascript doesn't really have different version numbers, and even when it does, the versions aren't particularly useful. The best way is to do feature detection. There are several projects and libraries which extend native types with features like Array.indexOf, Object.keys, addEventListener, etc. Like http://devpro.it/JSL/ and https://code.google.com/p/ddr-ecma5/

    0 讨论(0)
  • 2020-12-21 22:37

    In the real world, Javascript has no meaningful version numbers, especially in IE.

    This isn't really possible.

    0 讨论(0)
  • 2020-12-21 22:43

    You shouldn't use the language attribute, it's oldschool and not really relevant in this day and age. In addition, there is no standard for relaying the version of Javascript cross-browser. Not to mention different browsers have inconsistent Javascript versions.

    0 讨论(0)
  • 2020-12-21 22:50

    Looking at the comment you made to @meder, I would highly recommend you to go for feature detection, for example, to detect if the indexOf method is available on Array objects:

    if (typeof Array.prototype.indexOf == 'function') {
      //...
    }
    

    The JavaScript (TM) version numbers refer to the Mozilla implementation of the ECMAScript Standard.

    In the early years, when the language attribute was widely used, you could for example specify "JavaScript1.2" to place code that was written for ECMAScript 2, but I wouldn't recommend you this approach nowadays.

    The only reason you might want to specify a JavaScript(TM) version, is because you really need to use a Mozilla-specific extension, for example the let keyword, generators, iterators, expression closures, etc...

    See also:

    • Which Javascript version(s) does IE8 supports?
    0 讨论(0)
提交回复
热议问题