<?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; JAVASCRIPT</title>
	<atom:link href="https://www.phppan.com/tag/javascript/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>
		<item>
		<title>执行ajax加载的页面中包含的javascript</title>
		<link>https://www.phppan.com/2009/11/ajax-javascript-onload/</link>
		<comments>https://www.phppan.com/2009/11/ajax-javascript-onload/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 04:05:39 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[程序相关]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=387</guid>
		<description><![CDATA[执行ajax加载的页面中包含的javascript 1、【使用iframe】 在需要加载的页面中添加一个ifr [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>执行ajax加载的页面中包含的javascript</p>
<p>1、【使用iframe】<br />
在需要加载的页面中添加一个iframe，如下</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;iframe style=&quot;display:none&quot; onload=&quot;javascript: close_ticket_onload()&quot;&gt;&lt;/iframe&gt;</pre></td></tr></table></div>

<p>onload中添加你所要调用的函数，如果加载的页面在弹出层中，此函数需要放在弹出此层的父页面！</p>
<p>2、【使用eval】<br />
如果使用innerHTML填充XMLHttp取得的数据。如：xxx.innerHTML=XMLHttp取得的数据<br />
这样是不会执行JS，添加eval方法就ok了：如：xxx.innerHTML=eval(返XMLHttp取得的数据);<br />
其它细节请移步：http://blog.zol.com.cn/881/article_880154.html</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2009/11/ajax-javascript-onload/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP_REFERER有效和无效的情况</title>
		<link>https://www.phppan.com/2009/11/http-referer-able-noable/</link>
		<comments>https://www.phppan.com/2009/11/http-referer-able-noable/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 00:59:44 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程序相关]]></category>
		<category><![CDATA[HTTP_REFERER]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[PHP应用]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=370</guid>
		<description><![CDATA[HTTP_REFERER有效和无效的情况 【准备】 test.php文件 echo $_SERVER['HTT [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>HTTP_REFERER有效和无效的情况</p>
<p>【准备】<br />
test.php文件</p>
<p>echo $_SERVER['HTTP_REFERER'];</p>
<p>【有效的情况】<br />
1、以iframe 形式调用地址，如下所示</p>
<p>2、以window.open调用，打开新页面<br />
    window.open(url);</p>
<p>3、使用window.location.replace在Firefox 和Chrome下可以获取HTTP_REFERER</p>
<p>    window.location.replace(url);</p>
<p>4、使用window.location.href在Firefox 和Chrome下可以获取HTTP_REFERER<br />
    window.location.href = url;</p>
<p>5、使用A标签跳转可以获取HTTP_REFERER</p>
<p>【无效的情况】<br />
1、使用函数 file_get_contents或file等函数调用URL地址，这个地址所在的文件无法获取HTTP_REFERER</p>
<p>2、使用window.location.replace在IE6、IE7、IE8下无法获取HTTP_REFERER<br />
    window.location.replace(url);</p>
<p>3、使用window.location.href在IE6、IE7、IE8下无法获取HTTP_REFERER<br />
    window.location.href = url;</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2009/11/http-referer-able-noable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON格式总结</title>
		<link>https://www.phppan.com/2009/10/json-summary/</link>
		<comments>https://www.phppan.com/2009/10/json-summary/#comments</comments>
		<pubDate>Wed, 07 Oct 2009 02:07:31 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[程序相关]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP扩展]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=299</guid>
		<description><![CDATA[【JSON是什么】 JSON，JavaScript Object Notation，一种更轻、更友好的用于接口 [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>【JSON是什么】<br />
JSON，JavaScript Object Notation，一种更轻、更友好的用于接口(AJAX、REST等)数据交换的格式。JSON是结构化数据串行化的文本格式，作为XML的一种替代品，用于表示客户端与服务器间数据交换有效负载的格式。它是从ECMAScript语言标准衍生而来的。JSON的设计目标是使它成为小的、轻便的、文本的，而且是JavaScript的一个子集。<br />
JSON能够描述四种简单的类型（字符串、数字、布尔值和null）和两种结构化类型（对象和数组）。</p>
<p>字符串(string)是零个或多个Unicode字符的序列。除了字符 &#8220;、\、/和一些控制符（\b，\f，\n，\r，\t）需要编码外，其他 Unicode 字符可以直接输出</p>
<p>对象(Object)是无次序的零个或多个名/值(name/value)对的集合，使用｛｝包含包含所有元素。这里的name是string类型，value则可以是string、number、boolean、null、Object或Array类型。</p>
<p>数组(Array)是零个或多个value的有序序列。JSON 还可以表示一个数组对象，使用 [] 包含所有元素，每个元素用逗号分隔，元素可以是任意的 Value。</p>
<p>Object 对象在 JSON 中是用 {} 包含一系列无序的 Key-Value 键值对表示的，key是string类型，value则可以是string、number、boolean、null、Object或Array类型。</p>
<p>&#8220;Object&#8221;和&#8221;Array&#8221;这两个术语来自JavaScript规范。</p>
<p>【JSON的优点】</p>
<ol>
<li> 数据格式比较简单, 易于读写, 格式都是压缩的, 占用带宽小</li>
<li> 易于解析, 客户端JavaScript可以简单的通过eval()进行JSON数据的读取</li>
<li> 支持多种语言, 包括ActionScript, C, C#, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby等语言服务器端语言, 便于服务器端的解析</li>
</ol>
<p>【JSON的缺点】</p>
<ol>
<li> 没有XML格式这么推广的深入人心和使用广泛, 没有XML那么通用性</li>
<li> JSON格式目前在Web Service中推广还属于初级阶段</li>
</ol>
<p>【在PHP中使用JSON】<br />
PHP中的json直接相关的函数只有json_encode和json_decode。其中json_encode只能接受 UTF-8 编码的字符串类型数据，所以此处我们可能用到iconv等编码转换函数。</p>
<p>在PHP５.2.0之后，可以使用json_encode直接操作服务器端的对象、数组等，能够直接生JSON格式, 便于客户端的访问提取。<br />
另外，由于PHP中的数组是以HASH链表存在，可以使用非数字的关键字作为下标，所以，如果我们需要生成的数据是数组而不是对象时，需要数据的下标满足如下要求：</p>
<ul>
<li> 必须是数字索引，</li>
<li> 必须从0开始，</li>
<li> 必须从小到依次增加，</li>
<li> 中间不可以弹跳下,</li>
<li> 位置不可变动.</li>
</ul>
<p>这是由于在JS中数组是0开始的顺序序列，其余都只能是哈希表对象。如果要使用数组，可以使用array_values()函数。</p>
<p>【小结】<br />
JSON 已经是 JavaScript. 标准的一部分。目前，主流的浏览器对 JSON 支持都非常完善。应用 JSON，我们可以从 XML 的解析中摆脱出来，对那些应用 Ajax 的 Web 2.0 网站来说，JSON 确实是目前最灵活的轻量级方案。</p>
<p>【参考资料】</p>
<p>http://ssgemail.javaeye.com/blog/36776</p>
<p>http://blog.csdn.net/kinglino520/archive/2009/03/30/4036449.aspx</p>
<p>http://hi.baidu.com/zhaofei299/blog/item/79ba4bf3473012c30b46e0d3.html</p>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2009/10/json-summary/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>window.open窗口名称的问题</title>
		<link>https://www.phppan.com/2009/09/window-open-name-question/</link>
		<comments>https://www.phppan.com/2009/09/window-open-name-question/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 01:32:33 +0000</pubDate>
		<dc:creator><![CDATA[admin]]></dc:creator>
				<category><![CDATA[程序相关]]></category>
		<category><![CDATA[JAVASCRIPT]]></category>
		<category><![CDATA[window.open参数]]></category>
		<category><![CDATA[window.open窗口名称]]></category>
		<category><![CDATA[新窗口打开]]></category>

		<guid isPermaLink="false">http://www.phppan.com/?p=231</guid>
		<description><![CDATA[今日在一页面中需要点击查询按钮据下拉选择弹出不同的统计结果页面。即使用如下代码： 【代码一】 1 2 3 4  [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>今日在一页面中需要点击查询按钮据下拉选择弹出不同的统计结果页面。即使用如下代码：</p>
<p>【代码一】</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
window.open (url, ‘newwindow’, 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, 
scrollbars=yes, resizable=yes,location=no, status=no');
&lt;/script&gt;</pre></td></tr></table></div>

<p>当多次点击按钮触发此事件时，无法选择哪种统计方式，显示的结果总是在一个页面打开，除非关闭这个页面才会重新打开页面。不懂，于是修改其各个参数。终于在改变了newwindow后才出现所要的效果（对于每种类别在不同的窗口中显示）。<br />
【所得】</p>
<p>Window.open的第二个参数是用来标记当前页面的子窗口的，可以存在多个标记为空’’的子窗口，但是对于一个不为空的标记，只能存在一个此标记的窗口。如【代码一】所示，此代码在一个页面，即使是多次触发，也只会打开一个页面，就算是其它参数不同。<br />
【简单示例】</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
   var url = &quot;index.html&quot;;
   window.open (url, 'name', 'height=600, width=800, top=0, left=0, toolbar=no, menubar=no, 
scrollbars=yes, resizable=yes,location=no, status=no');
&lt;/script&gt;</pre></td></tr></table></div>

<p>附 参数详解【google所得】</p>
<p>【参数描述】</p>
<table border="0">
<tbody>
<tr>
<td>参数名</td>
<td>参数说明</td>
</tr>
<tr>
<td>url</td>
<td>弹出窗口的文件名</td>
</tr>
<tr>
<td>name</td>
<td>弹出窗口的名字（不是文件名），非必须，可用空&#8221;代替</td>
</tr>
<tr>
<td>height</td>
<td>窗口高度</td>
</tr>
<tr>
<td>width</td>
<td>窗口宽度</td>
</tr>
<tr>
<td>top</td>
<td>窗口距离屏幕上方的象素值</td>
</tr>
<tr>
<td>left</td>
<td>窗口距离屏幕左侧的象素值</td>
</tr>
<tr>
<td>toolbar</td>
<td>是否显示工具栏，yes为显示</td>
</tr>
<tr>
<td>menubar，scrollbars</td>
<td>表示菜单栏和滚动栏</td>
</tr>
<tr>
<td>resizable</td>
<td>是否允许改变窗口大小，yes为允许</td>
</tr>
<tr>
<td>location</td>
<td>是否显示地址栏，yes为允许</td>
</tr>
<tr>
<td>status</td>
<td>是否显示状态栏内的信息（通常是文件已经打开），yes为允许</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>https://www.phppan.com/2009/09/window-open-name-question/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
