Home > Web Front-end > JS Tutorial > Code to determine the browser's javascript version_javascript skills

Code to determine the browser's javascript version_javascript skills

WBOY
Release: 2016-05-16 18:20:23
Original
1138 people have browsed it

He said that the code to be executed should be nested as shown in < script language="JavaScript1.2" >. But when asked to detect the javascript version, I got the following code:

Copy the code The code is as follows:

var JS_ver = [];
(Number.prototype.toFixed)?JS_ver.push("1.5"):false;
([].indexOf && [].forEach)?JS_ver.push("1.6 "):false;
((function(){try {[a,b] = [0,1];return true;}catch(ex) {return false;}})())?JS_ver.push ("1.7"):false;
([].reduce && [].reduceRight && JSON)?JS_ver.push("1.8"):false;
("".trimLeft)?JS_ver.push( "1.8.1"):false;
JS_ver.supports = function()
{
if (arguments[0])
return (!!~this.join().indexOf(arguments [0] ",") ",");
else
return (this[this.length-1]);
}
alert("Latest Javascript version supported: " JS_ver.supports ());
alert("Support for version 1.7 : " JS_ver.supports("1.7"));

This script can not only detect the JavaScript version by detecting features, but also Check the features supported by a specific Javascript version.
We got the result, let’s take a look at how this system detects the javascript version, so we extracted the code (the extraction process was quite tangled) and got the following code:
Copy code The code is as follows:



Code implementation principle: according to different versions JavaScript has different support for some specific functions to determine its version. There is only one special treatment for version 1.4.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template