告诉你的浏览器的JavaScript版本 [英] To tell Javascript version of your browser
问题描述
我从 http://javascript.about.com/library/bljver下面的脚本。 HTM
<script type="text/javascript">
var jsver = 1.0;
</script>
<script language="Javascript1.1">
jsver = 1.1;
</script>
<script language="Javascript1.2">
jsver = 1.2;
</script>
<script language="Javascript1.3">
jsver = 1.3;
</script>
<script language="Javascript1.4">
jsver = 1.4;
</script>
<script language="Javascript1.5">
jsver = 1.5;
</script>
<script language="Javascript1.6">
jsver = 1.6;
</script>
<script type="text/javascript">
document.write('<p><b>Javascript version ' + jsver + ' supported<\/b><\/p>');
</script>
但不知道是否有一个较短的方式?
but wonder if there is a shorter way?
推荐答案
综观评论你<一做href=\"http://stackoverflow.com/questions/3242109/to-tell-javascript-version-of-your-browser/3242127#3242127\">@meder,我会强烈建议你去的特征检测的,例如,以检测是否在的indexOf
法可在Array对象:
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') {
//...
}
的的JavaScript(TM)的版本号指的 Mozilla的实施ECMAScript标准的
在早些年,当语言
属性被广泛使用,例如,你可以指定JavaScript1.2
放置这对ECMAScript的2书面code,但我不会今天推荐你这种方法。
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.
您可能要指定的的JavaScript(TM)的版本的唯一原因,是因为你真的需要使用的 Mozilla的特定扩展,<一个href=\"http://stackoverflow.com/questions/2356830/what-browsers-currently-support-javascripts-let-keyword/2356926#2356926\">for例如,从而让
关键字,发电机,迭代器,前pression封闭等...
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...
另请参阅:
- Which Javascript version(s) does IE8 supports?
这篇关于告诉你的浏览器的JavaScript版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!