Reputation: 3474
We are starting a project and want to be cross-browser compatible - this would seem to suggest that we need to ensure that the version of JavaScript we're using is works in all of the browsers we intend to support. Is the following a reasonable way to test to see what the JavaScript level works in each browser?
<script language="javascript1.0">alert("Your browser at least supports JavaScript 1.0");</script>
<script language="javascript1.1">alert("Your browser at least supports JavaScript 1.1");</script>
<script language="javascript1.2">alert("Your browser at least supports JavaScript 1.2");</script>
<script language="javascript1.3">alert("Your browser at least supports JavaScript 1.3");</script>
<script language="javascript1.4">alert("Your browser at least supports JavaScript 1.4");</script>
<script language="javascript1.5">alert("Your browser at least supports JavaScript 1.5");</script>
<script language="javascript1.6">alert("Your browser at least supports JavaScript 1.6");</script>
<script language="javascript1.7">alert("Your browser at least supports JavaScript 1.7");</script>
<script language="javascript1.8">alert("Your browser at least supports JavaScript 1.8");</script>
Obviously the list of tests could be extended as further JavaScript versions are released.
Is there a better way (or source) for this information?
By the way, I did see the Wikipedia page on JavaScript versions and it doesn't seem to correspond to the results I get when I run the code snippet above.
My results are:
Firefox 43.0.4 - reports as supporting JavaScript 1.0 through 1.5
IE 10.0.9200.17566 - reports as supporting JavaScript 1.1 through 1.3
Chrome Version 47.0.2526.111 m - reports as supporting JavaScript 1.0 through 1.7
Safari 5.1.7 (7534.57.2) - reports as supporting JavaScript 1.0 through 1.7
Opera 34.0.2036.50 - reports as supporting JavaScript 1.0 through 1.7
Upvotes: 0
Views: 4723
Reputation: 179046
Is the following a reasonable way to test to see what the JavaScript level works in each browser?
No.
Don't use the [language]
attribute, it's only going to cause you incompatibility, especially as time goes on and newer browsers decide they only support javascript3.8
or whatever the version-du-jour happens to be. If you want to write a script, just write a script:
<script src="filename.js"></script>
As far as detecting versions, you don't need to detect JS versions. No developer worth their salt checks versions, they check features. Modernizr is one such feature detection resource. caniuse is another which describes which browsers support which features so you can determine if you're going to be able to use any particular feature at all.
In many cases, what you'll want for maximum backwards compatibility is a set of polyfills to replicate any newer features you'd like to use for older browsers.
Upvotes: 8