Not there is a reliable way to discover the Javascript version.
The use of <script language="Javascript1.*">
has not precision, an example of problem is that in some browsers you can use an attribute language="Javascript1.7"
but still you can use only supported functions in language="Javascript1.9"
.
Another problem is in the Internetexplorer9 for example, it supports various features that should already be at least Javascript1.5, but he always presents Javascript1.3.
The same is true of Firefox, which always displays the result of Javascript1.5.
As stated in other answers there is no function to detect the version of the Javascript engine, note that each browser has a javascript engine own and often such version does not represent the functionalities it actually possesses.
If you rely on such data you are able to disable useful and supported functions that logic should not support in such version of Javascript.
This is because in fact since the beginning of the browser battle, when microsoft launched its own javascript engine (called jscript
) and Netscape released his, with many different characteristics (as amazing as it seems the Internetexplorer at that time was much better at it than the competitors).
There was no pattern and only with the emergence of Ecmascript we now have a standard (the development of this specification began in November 1996 and was adopted by Ecma General Assembly in June 1997, according to the pdf document in the cited link).
I believe that today we are in Ecmascript 7, but it does not mean that browsers support all features.
Look at it this way, imagine that we have two technologies of Ecmascript 6 (it’s just an imaginary example):
window.minhaFuncaoHelloWordEcma6
window.minhaFuncaoFooEcma6
Chorme launched the function window.minhaFuncaoHelloWordEcma6
, but can’t stand window.minhaFuncaoFooEcma6
, then the browser cannot be Ecmascript6 nor Ecmascript5 because in 5 there is no window.minhaFuncaoHelloWordEcma6
and to be the 6 is necessary window.minhaFuncaoFooEcma6
.
So identifying the Javascript or Ecmascript version will never be possible, unless all browsers strictly follow the standard and only support new methods when they all cease to be experimental (or that it is unviable and would make the update process much slower).
Note that today we use many experimental features, so do not use:
<script language="Javascript1.9">
jsver = 1.9;
</script>
Because you will never get the expected result in different browsers.
Javascript and Mozilla
As per this comment on Soen:
Google-Chrome support Ecmascript 3.1 and Parts of Ecmascript 5. Javascript 1.7 is a Mozilla Creation. No other browsers support Javascript > 1.5, and Instead support Varying versions of Ecmascript. See Relationship between Javascript and Ecmascript version Numbers - Mike Samuel
And the @bfavareto comment:
Don’t you want to add that these "1.x" versions are only valid for Mozilla browsers? That is who has the trademark copyright Javascript, by the way. - bfavaretto
This free program was originally developed by Brendan Eich of Netscape under the name of Mocha, later changed its name to Livescript and finally Javascript.
As a consequence, Microsoft has developed a dialect compatible with the Jscript name language to avoid trademark problems, in other words the terms Javascript is was registered by the old Netscape (today Mozilla - I’m talking about the company).
So Javascript1.7 is a Mozilla creation and so most browsers "non Mozilla", will only work until javascript1.3 or javascript1.5, as they have standardized to follow the versions of ES deployments, so what updates today is the Javascript engine (next to the browser).
Source: https://en.wikipedia.org/wiki/JavaScript
Completion
- Unable to detect Javascript version
- Even if the browser says that it is using Javascript1.3 it may already be in a much higher supposed version
- A browser can supposedly use a version of Javascript and present some "Features" which should not exist in such a version.
- Cannot detect the full compatibility version with Ecmascript versions (unless you create a library with all kinds of possible tests, which seems impossible)
Follow what @Maniero said, use the Feature Detection
Recommending
I recommend that instead of detecting the Javascript or Ecmascript version try to detect if the function is supported, for example:
function minhaFuncao(arg1) {
if (typeof window.minhaFuncaoFooEcma6 === "function") {
return window.minhaFuncaoFooEcma6(arg1);
}
return false;
}
Note: In another reply of mine I add some examples of how to detect the functionalities in a more "secure way": How to Detect DOM and API Resources
Just out of curiosity, what’s the point?
– Maicon Carraro
Know the javascript version :D
– Wallace Maxters
In fact, it might be useful if some feature was missing in an earlier version
– Wallace Maxters
See if this helps: http://stackoverflow.com/questions/7340726/detect-version-of-javascript (útlima resposta)
– cantoni
Could someone explain why Downvote? When I give Downvote, I do it with purpose!
– Wallace Maxters
Some people do it for pure luxury. Some questions are good, go downvote people and do not give an opinion for the reason why voted this way, leaving the person with the doubt and no answer.
– Filipe Machado