<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>潘锦的空间 &#187; 特征检测</title>
	<atom:link href="https://www.phppan.com/tag/%e7%89%b9%e5%be%81%e6%a3%80%e6%b5%8b/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.phppan.com</link>
	<description>SaaS SaaS架构 团队管理 技术管理 技术架构 PHP 内核 扩展 项目管理</description>
	<lastBuildDate>Sat, 25 Apr 2026 00:56:17 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=3.9.40</generator>
	<item>
		<title>如何判断浏览器的javascript版本</title>
		<link>https://www.phppan.com/2010/09/how-to-check-javascript-version/</link>
		<comments>https://www.phppan.com/2010/09/how-to-check-javascript-version/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 16:03:27 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[程序相关]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[Javascript版本]]></category>
		<category><![CDATA[特征检测]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=969</guid>
		<description><![CDATA[如何判断浏览器的javascript版本 话说最近在研究某著名跟踪系统，在其给用户的实施代码中有一段判断浏览器 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>如何判断浏览器的javascript版本</p>
<p>话说最近在研究某著名跟踪系统，在其给用户的实施代码中有一段判断浏览器Javascript版本的代码引起了我的注意，于是问了下google如何判断浏览器的javascript版本，他老人家说将所要执行的代码放在如< script language="JavaScript1.2" >所示嵌套下。但是当问到检测javascript版本时，得到如下代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">var JS_ver  = [];
(Number.prototype.toFixed)?JS_ver.push(&quot;1.5&quot;):false;
([].indexOf &amp;&amp; [].forEach)?JS_ver.push(&quot;1.6&quot;):false;
((function(){try {[a,b] = [0,1];return true;}catch(ex) {return false;}})())?JS_ver.push(&quot;1.7&quot;):false;
([].reduce &amp;&amp; [].reduceRight &amp;&amp; JSON)?JS_ver.push(&quot;1.8&quot;):false;
(&quot;&quot;.trimLeft)?JS_ver.push(&quot;1.8.1&quot;):false;
JS_ver.supports = function()
{
if (arguments[0])
&nbsp;
return (!!~this.join().indexOf(arguments[0] +&quot;,&quot;) +&quot;,&quot;);
else
&nbsp;
return (this[this.length-1]);
}
alert(&quot;Latest Javascript version supported: &quot;+ JS_ver.supports());
alert(&quot;Support for version 1.7 : &quot;+ JS_ver.supports(&quot;1.7&quot;));</pre></td></tr></table></div>

<p><strong>这个脚本，既能通过检测特征来检测JavaScript版本，还能检查特定的Javascript版本所支持的特性。</strong></p>
<p>得到了结果，我们还是看下此系统是如何检测javascript版本的吧，于是将其代码抽取出来（抽取过程相当纠结），得到如下所示代码：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
var n = navigator;
var u = n.userAgent;
&nbsp;
var apn = n.appName;
var v = n.appVersion;
var ie = v.indexOf('MSIE ')
if(ie &gt; 0){
   apv = parseInt(i = v.substring(ie + 5));
   if(apv &gt; 3) {
       apv = parseFloat(i);
   }
}else{
   apv = parseFloat(v);
}
&nbsp;
var isie = (apn == 'Microsoft Internet Explorer');
var ismac = (u.indexOf('Mac') &gt;= 0);
&nbsp;
var javascriptVersion = &quot;1.0&quot;;
&nbsp;
if(String &amp;&amp; String.prototype){
   javascriptVersion = '1.1';
&nbsp;
   if(javascriptVersion.match){
       javascriptVersion = '1.2';
&nbsp;
       var tm = new Date;
       if(tm.setUTCDate){
           javascriptVersion = '1.3';
&nbsp;
           if(isie &amp;&amp; ismac &amp;&amp; apv &gt;= 5) javascriptVersion = '1.4';
&nbsp;
           var pn = 0;
           if(pn.toPrecision){
               javascriptVersion = '1.5';
&nbsp;
               a = new Array;
               if(a.forEach){
                   javascriptVersion = '1.6';
&nbsp;
                   i = 0;
                   o = new Object;
                   tcf = new Function('o','var e,i=0;try{i=new Iterator(o)}catch(e){}return i');
                   i = tcf(o);
                   if(i &amp;&amp; i.next) {
                       javascriptVersion = '1.7';
                   }
               }
           }
       }
   }
}
alert(javascriptVersion);
&lt;/script&gt;</pre></td></tr></table></div>

<p>代码实现原理：<strong>根据不同版本的javascript对于一些特定函数的支持不同从而判断其版本所在。其中仅对1.4版本有一个特殊处理。</strong></p>
<p>&#8211;EOF&#8211;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2010/09/how-to-check-javascript-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
