Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect version of JavaScript

Tags:

javascript

How can I detect what version of JavaScript the browser supports (if any)? I want to check for ECMAScript 3 versus ECMAScript 5 versus ECMAScript 6.

Note: I want to avoid the deprecated language tag.

like image 615
Randomblue Avatar asked Sep 07 '11 21:09

Randomblue


People also ask

How do I find the version of JavaScript?

Visit the System information tool to see what version of JavaScript is detected. JavaScript is browser dependent, which means the version of JavaScript detected may be different in Firefox than the version detected by Internet Explorer.

How do I know what version of ECMAScript I have?

ECMAScript support different object on each version. To detect the ECMAScript version we can check the object exits into a browser or not. If that object is identified that means ECMA Version supported into the browser.

How do I check JavaScript version in browser console?

On Chromium chrome://version/ give the name and version of the JS Engine (V8).


2 Answers

Here is a good reference for you: http://www.docsteve.com/DocSteve/Samples/JS/js_version.html

Basically, use the deprecated language attribute of the script tag

<script language="javascript">var js_version="1.0"</script> <script language="javascript1.1">var js_version="1.1"</script> <script language="javascript1.2">var js_version="1.2"</script> <script language="javascript1.3">var js_version="1.3"</script> <script language="javascript1.4">var js_version="1.4"</script> <script language="javascript1.5">var js_version="1.5"</script> <script language="javascript1.6">var js_version="1.6"</script> 
like image 175
Naftali Avatar answered Sep 20 '22 10:09

Naftali


The solution proposed to http://www.docsteve.com/DocSteve/Samples/JS/js_version.html as simple JavaScript function (using "createElement" construction):

<script type="text/javascript"> function get_js_version () {     this.jsv = {             versions: [                 "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2.0"             ],             version: ""         };      var d = document;      for (i = 0; i < jsv.versions.length; i++) {         var g = d.createElement('script'),             s = d.getElementsByTagName('script')[0];              g.setAttribute("language", "JavaScript" + jsv.versions[i]);             g.text = "this.jsv.version='" + jsv.versions[i] + "';";             s.parentNode.insertBefore(g, s);     }      return jsv.version; }  document.write('JavaScript Version: ' + get_js_version()); </script> 
like image 36
DmitryS Avatar answered Sep 23 '22 10:09

DmitryS