<?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>Leakon</title>
	<atom:link href="http://www.leakon.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leakon.com</link>
	<description>勤奋 - 创新 - 矢志不渝 - 锲而不舍</description>
	<lastBuildDate>Sat, 24 Jul 2010 14:50:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Iframe Tips ABC</title>
		<link>http://www.leakon.com/archives/663</link>
		<comments>http://www.leakon.com/archives/663#comments</comments>
		<pubDate>Sat, 24 Jul 2010 14:50:31 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[IEJS]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=663</guid>
		<description><![CDATA[
通常我们用 js 脚本创建 iframe 时，会这样写：
var iframe = document.createElement('iframe');
之后我们可能会定义 id、name、border 等属性，这些看似简单，其实 IE 与非 IE 浏览器之间、IE 和 IE 高版本之间的迥异，使得 iframe 的相关兼容性操作非常地有文章。
牛A：frameborder
现象：使用 (iframe.frameBorder = 数值) 或(iframe.setAttribute(‘frameborder’,数值)) 在 IE 浏览器下无效原因：IE 浏览器区分属性名称大小写解决方法：iframe.setAttribute(‘frameBorder’,'0′) Or iframe.setAttribute(‘frameborder’,'0′,0)，兼容所有浏览器。
注：经测试，IE8已经修复此问题
牛B：动态将Form target到iframe
背景：假设现在我们要让一个 Form 表单结果提交到一个 HTML 结构中已存在的 iframe，会这样做：
&#60;form id="form" name="form" target="相应iframe的name:iframeNB" method="post" &#62;&#60;/form&#62;&#60;iframe name="iframeNB" &#62;&#60;/iframe&#62;
OK，什么问题也没有，再假设我们需要提交到脚本动态生成的 iframe 中，会这样做：
&#60;form id="form" name="form" target="iframeNB" method="post" &#62;&#60;/form&#62;&#60;script&#62;var iframe = document.createElement('iframe');iframe.name = 'iframeNB';...someParent.appendChild(iframe);&#60;/script&#62;
去 IE [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-align: left;"></p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">通常我们用 js 脚本创建 iframe 时，会这样写：</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">var iframe = document.createElement('iframe');</code></p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">之后我们可能会定义 id、name、border 等属性，这些看似简单，其实 IE 与非 IE 浏览器之间、IE 和 IE 高版本之间的迥异，使得 iframe 的相关兼容性操作非常地有文章。</p>
<h3 style="margin: 0px; padding: 0px; color: #3e606f; font-size: 18px; line-height: 23px;">牛A：frameborder</h3>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">现象：使用 (iframe.frameBorder = 数值) 或(iframe.setAttribute(‘frameborder’,数值)) 在 IE 浏览器下无效<br style="margin: 0px; padding: 0px;" />原因：IE 浏览器区分属性名称大小写<br style="margin: 0px; padding: 0px;" />解决方法：iframe.setAttribute(‘frameBorder’,'0′) Or iframe.setAttribute(‘frameborder’,'0′,0)，兼容所有浏览器。</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">注：经测试，IE8已经修复此问题</p>
<h3 style="margin: 0px; padding: 0px; color: #3e606f; font-size: 18px; line-height: 23px;">牛B：动态将Form target到iframe</h3>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">背景：假设现在我们要让一个 Form 表单结果提交到一个 HTML 结构中已存在的 iframe，会这样做：</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">&lt;form id="form" name="form" target="相应iframe的name:iframeNB" method="post" &gt;<br style="margin: 0px; padding: 0px;" />&lt;/form&gt;<br style="margin: 0px; padding: 0px;" />&lt;iframe name="iframeNB" &gt;&lt;/iframe&gt;</code></p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">OK，什么问题也没有，再假设我们需要提交到脚本动态生成的 iframe 中，会这样做：</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">&lt;form id="form" name="form" target="iframeNB" method="post" &gt;<br style="margin: 0px; padding: 0px;" />&lt;/form&gt;<br style="margin: 0px; padding: 0px;" />&lt;script&gt;<br style="margin: 0px; padding: 0px;" />var iframe = document.createElement('iframe');<br style="margin: 0px; padding: 0px;" />iframe.name = 'iframeNB';<br style="margin: 0px; padding: 0px;" />...<br style="margin: 0px; padding: 0px;" />someParent.appendChild(iframe);<br style="margin: 0px; padding: 0px;" />&lt;/script&gt;</code></p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">去 IE 浏览器里试试，你会发现 Form 会在新窗口显示提交结果，Why?<br style="margin: 0px; padding: 0px;" />原因：<br style="margin: 0px; padding: 0px;" />我为此尝试了很久，结果是IE此前版本不能通过(iframe.name=)这种方式给 iframe 设置 name 值，也就是说生成的 iframe 是没有 name 值的，但却可以 alert 出来，这很诡异；当然，这也并不是没有解决办法。<br style="margin: 0px; padding: 0px;" />解决方法，为此我们得为 IE 单独写一行代码：</p>
<pre style="margin: 0px; padding: 5px; overflow-x: auto;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">  <span style="margin: 0px; padding: 0px; color: gray;">/*only for ie */</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">var</span> iframe = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">'&lt;iframe name="iframeNB"&gt;'</span>); <br style="margin: 0px; padding: 0px;" /></code></pre>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">看到这行代码，我们笑了，这是天大的杯具（喜剧？）～～不管IE有多么搓的问题，他总会有自己一套解决之……<br style="margin: 0px; padding: 0px;" />而且这行代码会在其他非 IE 浏览器抛出异常，所以我们可以利用这点来做最终版：</p>
<pre style="margin: 0px; padding: 5px; overflow-x: auto;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">    <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">var</span> iframe; <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">try</span><span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        iframe = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">'&lt;iframe name="iframeNB"&gt;'</span>); <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span><span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">catch</span>(e)<span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        iframe = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">'iframe'</span>); <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <br style="margin: 0px; padding: 0px;" />    iframe.name = <span style="margin: 0px; padding: 0px; color: teal;">'iframeNB'</span>; <br style="margin: 0px; padding: 0px;" />    ... <br style="margin: 0px; padding: 0px;" />    someParent.appendChild(iframe); <br style="margin: 0px; padding: 0px;" />    ... <br style="margin: 0px; padding: 0px;" /></code></pre>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">[2009-12-9]补充：最佳实践 – YUI 是如何 creat iframe 的</p>
<pre style="margin: 0px; padding: 5px; overflow-x: auto;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">    <span style="margin: 0px; padding: 0px; color: gray;">/** <br style="margin: 0px; padding: 0px;" />    * @description Creates an iframe to be used for form file uploads.  It is remove from the <br style="margin: 0px; padding: 0px;" />    * document upon completion of the upload transaction. <br style="margin: 0px; padding: 0px;" />    * @method createFrame <br style="margin: 0px; padding: 0px;" />    * @private <br style="margin: 0px; padding: 0px;" />    * @static <br style="margin: 0px; padding: 0px;" />    * @param {string} optional qualified path of iframe resource for SSL in IE. <br style="margin: 0px; padding: 0px;" />    * @return {void} <br style="margin: 0px; padding: 0px;" />    */</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: #4169e1; font-weight: bold;">function</span> _createFrame(secureUri)<span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: green;">// IE does not allow the setting of id and name attributes as object</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: green;">// properties via createElement().  A different iframe creation</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: green;">// pattern is required for IE.</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">var</span> frameId = <span style="margin: 0px; padding: 0px; color: teal;">'yuiIO'</span> + <span style="margin: 0px; padding: 0px; color: #4169e1; font-weight: bold;">this</span>._transaction_id,io; <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">if</span>(YAHOO.env.ua.ie)<span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        io = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">'&lt;iframe id="'</span> + frameId + <span style="margin: 0px; padding: 0px; color: teal;">'"name="'</span> + frameId + <span style="margin: 0px; padding: 0px; color: teal;">'" /&gt;'</span>); <br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; color: green;">// IE will throw a security exception in an SSL environment if the</span> <br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; color: green;">// iframe source is undefined.</span> <br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">if</span>(<span style="margin: 0px; padding: 0px; color: #4169e1; font-weight: bold;">typeof</span> secureUri == <span style="margin: 0px; padding: 0px; color: teal;">'boolean'</span>)<span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />            io.src = <span style="margin: 0px; padding: 0px; color: teal;">'javascript:false'</span>; <br style="margin: 0px; padding: 0px;" />        <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span><span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">else</span><span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        io = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">'iframe'</span>); <br style="margin: 0px; padding: 0px;" />        io.id = frameId; <br style="margin: 0px; padding: 0px;" />        io.name = frameId; <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <br style="margin: 0px; padding: 0px;" />    io.style.position = <span style="margin: 0px; padding: 0px; color: teal;">'absolute'</span>; <br style="margin: 0px; padding: 0px;" />    io.style.top = <span style="margin: 0px; padding: 0px; color: teal;">'-1000px'</span>; <br style="margin: 0px; padding: 0px;" />    io.style.left = <span style="margin: 0px; padding: 0px; color: teal;">'-1000px'</span>; <br style="margin: 0px; padding: 0px;" />    document.body.appendChild(io); <br style="margin: 0px; padding: 0px;" />    YAHOO.log(<span style="margin: 0px; padding: 0px; color: teal;">'File upload iframe created. Id is:'</span> + frameId, <span style="margin: 0px; padding: 0px; color: teal;">'info'</span>, <span style="margin: 0px; padding: 0px; color: teal;">'Connection'</span>); <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <br style="margin: 0px; padding: 0px;" /></code></pre>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">这里需要额外注意到的一点是：</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;">// IE will throw a security exception in an SSL environment if the<br style="margin: 0px; padding: 0px;" />// iframe source is undefined.<br style="margin: 0px; padding: 0px;" />if(typeof secureUri == 'boolean'){<br style="margin: 0px; padding: 0px;" />io.src = 'javascript:false';<br style="margin: 0px; padding: 0px;" />}</code></p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">姑且算是牛D吧 =.=!</p>
<h3 style="margin: 0px; padding: 0px; color: #3e606f; font-size: 18px; line-height: 23px;">牛C：iframe.onload</h3>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">关于 onload 这点大家可以参考<a style="margin: 0px 2px; padding: 0px; color: #0066cc; text-decoration: none; outline-style: none;" href="http://www.planabc.net/" target="_blank">怿飞师父</a>的文章：<a style="margin: 0px 2px; padding: 0px; color: #0066cc; text-decoration: none; outline-style: none;" href="http://www.planabc.net/2009/09/22/iframe_onload/" target="_blank">判断 iframe 是否加载完成的完美方法</a>，在此纯引用一次代码：</p>
<pre style="margin: 0px; padding: 5px; overflow-x: auto;"><code style="margin: 10px 20px; padding: 0px 5px 2px; background-color: #fafafa; font-family: 'Courier New',Courier; border: 1px dashed #dddddd; color: #777777; line-height: 23px; display: block;"><span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">var</span> iframe = document.createElement(<span style="margin: 0px; padding: 0px; color: teal;">"iframe"</span>); <br style="margin: 0px; padding: 0px;" />iframe.src = <span style="margin: 0px; padding: 0px; color: teal;">"http://www.planabc.net"</span>; <br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">if</span> (iframe.attachEvent) <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />    iframe.attachEvent(<span style="margin: 0px; padding: 0px; color: teal;">"onload"</span>, <span style="margin: 0px; padding: 0px; color: #4169e1; font-weight: bold;">function</span> () <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        alert(<span style="margin: 0px; padding: 0px; color: teal;">"Local iframe is now loaded."</span>); <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span>); <br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <span style="margin: 0px; padding: 0px; color: navy; font-weight: bold;">else</span> <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />    iframe.onload = <span style="margin: 0px; padding: 0px; color: #4169e1; font-weight: bold;">function</span> () <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">{</span> <br style="margin: 0px; padding: 0px;" />        alert(<span style="margin: 0px; padding: 0px; color: teal;">"Local iframe is now loaded."</span>); <br style="margin: 0px; padding: 0px;" />    <span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span>; <br style="margin: 0px; padding: 0px;" /><span style="margin: 0px; padding: 0px; color: red; font-weight: bold;">}</span> <br style="margin: 0px; padding: 0px;" />document.body.appendChild(iframe); <br style="margin: 0px; padding: 0px;" /></code></pre>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;"><strong style="margin: 0px; padding: 0px;">需要注意到的是：</strong></p>
<ul style="margin: 10px 0px; padding: 0px 40px;">
<li style="margin: 0px; padding: 2px 0px;">IE8也不支持iframe.onload</li>
<li style="margin: 0px; padding: 2px 0px;">Opera两者均可，所以使用此方法会绑定前者</li>
<li style="margin: 0px; padding: 2px 0px;">即使我们不预设iframe.src = some urls，也会默认执行一次onload事件，可以通过分析 src 规避。</li>
</ul>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">附测试文件：<br style="margin: 0px; padding: 0px;" />1.<a style="margin: 0px 2px; padding: 0px; color: #0066cc; text-decoration: none; outline-style: none;" href="http://www.silentash.com.previewdns.com/upload/iframe_ie_ugly.html" target="_blank">iframe_ie_ugly.html</a><br style="margin: 0px; padding: 0px;" />2.<a style="margin: 0px 2px; padding: 0px; color: #0066cc; text-decoration: none; outline-style: none;" href="http://www.silentash.com.previewdns.com/upload/iframe_fixed.html" target="_blank">iframe_fixed.html</a><br style="margin: 0px; padding: 0px;" />以上，我认为 ABC 中最牛的就是 B 了，这也是我标题的亮点=.=! 斯密达们认为呢？</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">上述文字转自 <a href="http://blog.silentash.com/2009/12/iframe-tips-abc/">http://blog.silentash.com/2009/12/iframe-tips-abc/</a>，感谢原作者给我提供的巨大帮助。</p>
<p style="margin: 5px 0px; padding: 5px 20px 5px 0px;">转载在这里与更多人分享。</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/663/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IE Bug Javascript</title>
		<link>http://www.leakon.com/archives/649</link>
		<comments>http://www.leakon.com/archives/649#comments</comments>
		<pubDate>Mon, 12 Jul 2010 05:15:13 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[IE]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=649</guid>
		<description><![CDATA[问题描述：
当 A 标签的文本是 http 开头时，设置 href 属性，会同时以相同的值更新链接文本，反之亦然。
解决方法：
在设置 href 时，在开头添加一个空格 ' '，即可解决此 bug。
测试 Demo:
http://code.leakon.com/javascript/set_href/set_href.html
注意，只在 IE 下会出现错误。
预期的功能是修改链接的 href 属性。
使用默认的修改方法有 bug，会把链接文本改掉！
]]></description>
			<content:encoded><![CDATA[<p>问题描述：<br />
当 A 标签的文本是 http 开头时，设置 href 属性，会同时以相同的值更新链接文本，反之亦然。</p>
<p>解决方法：<br />
在设置 href 时，在开头添加一个空格 ' '，即可解决此 bug。</p>
<p>测试 Demo:</p>
<p><a href="http://code.leakon.com/javascript/set_href/set_href.html" target="_blank">http://code.leakon.com/javascript/set_href/set_href.html</a></p>
<p>注意，只在 IE 下会出现错误。</p>
<p>预期的功能是修改链接的 href 属性。</p>
<p>使用默认的修改方法有 bug，会把链接文本改掉！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/649/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0x80040111 NS_ERROR_NOT_AVAILABLE</title>
		<link>http://www.leakon.com/archives/647</link>
		<comments>http://www.leakon.com/archives/647#comments</comments>
		<pubDate>Thu, 08 Jul 2010 09:00:51 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=647</guid>
		<description><![CDATA[Firefox 在处理 Ajax 遇到错误时会报 0x80040111 异常。
在网上查了下，有的说法是，在很短的时间间隔发送了 2 次 Ajax 请求，XMLHttpRequest 的值还没有返回回来就又被请求了一次。
还有一个情况，是我遇到的，在请求成功返回后执行回调函数时，引用了空对象的属性，debug 报错："null  has no properties"。
目前只遇到这 2 种情况，记录备忘。
]]></description>
			<content:encoded><![CDATA[<p>Firefox 在处理 Ajax 遇到错误时会报 0x80040111 异常。</p>
<p>在网上查了下，有的说法是，在很短的时间间隔发送了 2 次 Ajax 请求，XMLHttpRequest 的值还没有返回回来就又被请求了一次。</p>
<p>还有一个情况，是我遇到的，在请求成功返回后执行回调函数时，引用了空对象的属性，debug 报错："<span id="zw-129b13b809dxRbTqCb0c29"><!-- table { font-size: 10pt;} -->null  has no properties</span>"。</p>
<p>目前只遇到这 2 种情况，记录备忘。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/647/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WinSCP UltraEdit Unix DOS Format</title>
		<link>http://www.leakon.com/archives/644</link>
		<comments>http://www.leakon.com/archives/644#comments</comments>
		<pubDate>Thu, 10 Jun 2010 05:39:56 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[非技术]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[UltraEdit]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=644</guid>
		<description><![CDATA[
用 WinSCP + UltraEdit，可以直接修改服务器上的文件，保存时自动上传到服务器上，用起来很方便。
最近发现个情况，服务器上的文件不管是 DOS 还是 Unix 格式，用 UltraEdit 打开总是显示 DOS 格式，保存后，却都变成了 Unix 格式！
反复检查了 UltraEdit 的设置选项，都没问题，编辑本机文件都是正常的。
后来开始怀疑 WinSCP。
费了好半天劲，终于找到原因，在 Editor 选项中可以设置外部编辑器，然后设置编辑器选项，如顶图所示红框的位置。
意思是，用编辑器传文件强制使用文本方式传输，这就是导致问题的关键点。
把这个选项去掉，打开文件格式可以正确识别，保存后格式也不会全部转换成 Unix 了。
记录 &#38; 分享。
]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-645" title="editor_transfer" src="http://www.leakon.com/wp-content/uploads/2010/06/editor_transfer.png" alt="editor_transfer" width="418" height="348" /></p>
<p>用 WinSCP + UltraEdit，可以直接修改服务器上的文件，保存时自动上传到服务器上，用起来很方便。</p>
<p>最近发现个情况，服务器上的文件不管是 DOS 还是 Unix 格式，用 UltraEdit 打开总是显示 DOS 格式，保存后，却都变成了 Unix 格式！</p>
<p>反复检查了 UltraEdit 的设置选项，都没问题，编辑本机文件都是正常的。</p>
<p>后来开始怀疑 WinSCP。</p>
<p>费了好半天劲，终于找到原因，在 Editor 选项中可以设置外部编辑器，然后设置编辑器选项，如顶图所示红框的位置。</p>
<p>意思是，用编辑器传文件强制使用文本方式传输，这就是导致问题的关键点。</p>
<p>把这个选项去掉，打开文件格式可以正确识别，保存后格式也不会全部转换成 Unix 了。</p>
<p>记录 &amp; 分享。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/644/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KB927917 IE 报错 解决方法</title>
		<link>http://www.leakon.com/archives/642</link>
		<comments>http://www.leakon.com/archives/642#comments</comments>
		<pubDate>Thu, 03 Jun 2010 05:56:55 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[Browser]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[KB927917]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=642</guid>
		<description><![CDATA[在 body 标签内调用 append 方式给 body 增加一个节点，如果此时 body 未加载完，也就是 body 标签还未关闭，IE 将报错：KB927917。
页面错误提示：Unable to modify the parent container element before the child element is closed.
查了下资料，知道了问题的产生原因：
首先是微软的详细解释：http://support.microsoft.com/kb/927917
最后发现其实微软的MSDN上早已列举了解决办法：
http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx
官方给出的解决办法如下：

Moving your script execution to a function that is invoked after parsing is complete (e.g., onload)
 Adding the defer boolean attribute to the script block (this defers execution of the script content [...]]]></description>
			<content:encoded><![CDATA[<p>在 body 标签内调用 append 方式给 body 增加一个节点，如果此时 body 未加载完，也就是 body 标签还未关闭，IE 将报错：KB927917。</p>
<p>页面错误提示：Unable to modify the parent container element before the child element is closed.</p>
<p>查了下资料，知道了问题的产生原因：</p>
<p>首先是微软的详细解释：http://support.microsoft.com/kb/927917</p>
<p>最后发现其实微软的MSDN上早已列举了解决办法：<br />
http://blogs.msdn.com/ie/archive/2008/04/23/what-happened-to-operation-aborted.aspx</p>
<p>官方给出的解决办法如下：</p>
<ol>
<li>Moving your script execution to a function that is invoked after parsing is complete (e.g., onload)</li>
<li> Adding the defer boolean attribute to the script block (this defers execution of the script content until parsing is complete)</li>
<li> Limiting your tree modifications to the script-element's immediate parent</li>
<li> Moving the location of your script block to a child of the body (this usually solves most problems, while allowing the most flexibility in terms of scenarios).</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/642/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>接到骗子来电 85928807</title>
		<link>http://www.leakon.com/archives/640</link>
		<comments>http://www.leakon.com/archives/640#comments</comments>
		<pubDate>Wed, 12 May 2010 05:57:04 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[默认分类]]></category>
		<category><![CDATA[骗子]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=640</guid>
		<description><![CDATA[刚接到一个电话：+000196852202，说我的工商银行信用卡在新世界消费9000多，让我尽快去银行缴费。有问题致电85928807，跟崇文区XXX行联系。
你MLGB，哥没有工行信用卡，你个SB。
骗子，各位小心！
]]></description>
			<content:encoded><![CDATA[<p>刚接到一个电话：+000196852202，说我的工商银行信用卡在新世界消费9000多，让我尽快去银行缴费。有问题致电85928807，跟崇文区XXX行联系。</p>
<p>你MLGB，哥没有工行信用卡，你个SB。</p>
<p>骗子，各位小心！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/640/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql 持久连接 mysql_connect mysql_pconnect</title>
		<link>http://www.leakon.com/archives/638</link>
		<comments>http://www.leakon.com/archives/638#comments</comments>
		<pubDate>Wed, 12 May 2010 03:52:28 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=638</guid>
		<description><![CDATA[在某些场合，mysql_pconnect( ) 是不适用的。
——————————————————————————–
状况一：
使用 1 部 web server 与 1 部 MySQL server（两者可能同在一部主机上），而 web server 固定只对 MySQL server 上的某一个数据库进行存取动作。
因为每次存取数据库时，都是由 web 那边使用同一账号对 MySQL 上的同一数据库作业，若我们将 MySQL 与 web server 的「同时联机数」都调整为 200，就好像 MySQL 这边一直有 200 位「服务生」，随时等着接待来自 web 的 200 位「顾客」似的。而且「顾客」离开之后，「服务生」也不下场休息，时时都站在门口等着接待下一个「顾客」。
在这种情况下，您只要注意将 MySQL 的「同时联机数」调得比 web server 的高或相等，就会发现使用 mysql_pconnect( ) 是个不错的选择。
——————————————————————————–
状况二：
使用 1 部 web server 与 1 部 MySQL server（两者可能同在一部主机上），而 web server [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: 'Lucida Grande',Verdana,Arial,sans-serif; font-size: 13px; line-height: 21px; text-align: left;">在某些场合，mysql_pconnect( ) 是不适用的。</p>
<p>——————————————————————————–</p>
<p>状况一：</p>
<p>使用 1 部 web server 与 1 部 MySQL server（两者可能同在一部主机上），而 web server 固定只对 MySQL server 上的某一个数据库进行存取动作。</p>
<p>因为每次存取数据库时，都是由 web 那边使用同一账号对 MySQL 上的同一数据库作业，若我们将 MySQL 与 web server 的「同时联机数」都调整为 200，就好像 MySQL 这边一直有 200 位「服务生」，随时等着接待来自 web 的 200 位「顾客」似的。而且「顾客」离开之后，「服务生」也不下场休息，时时都站在门口等着接待下一个「顾客」。</p>
<p>在这种情况下，您只要注意将 MySQL 的「同时联机数」调得比 web server 的高或相等，就会发现使用 mysql_pconnect( ) 是个不错的选择。<br />
——————————————————————————–</p>
<p>状况二：</p>
<p>使用 1 部 web server 与 1 部 MySQL server（两者可能同在一部主机上），而 web server 会对 MySQL server 上的两个数据库进行存取动作。</p>
<p>从 web server 那边提出数据存取需求时，有时是针对第 1 个数据库（DB1），有时则是针对第 2 个数据库（DB2）。若我们也将 MySQL 与 web server 的「同时联机数」都调整为 200，这样一来，就好像 MySQL 这边有 200 位「服务生」，但同时经营两个「吧台」（DB1 与 DB2），而「顾客」可能多达 200 位。</p>
<p>一开始，DB1 这个「吧台」比较热门，MySQL 派了 150 位「服务生」上场接待；同样地，当「顾客」离开之后，这 150 位「服务生」仍守着 DB1 而不下场休息。后来，DB2 那边也热闹起来了，「顾客」越来越多，MySQL 得加派「服务生」上场，有几个能派？答案是 50 个！</p>
<p>为什么「服务生」的人力调配会捉襟见肘？那是因为 web 那边使用了 mysql_pconnect( ) 来建立联机。「服务生」一开始被指定到哪个「吧台」工作，就会持续在那边停留，绝不「转台」。<br />
——————————————————————————–</p>
<p>请注意，当使用持续性的联机时，每个已建立的联机只为来自同一部 web server、使用同一组账号，且存取同一数据库的使用者服务。</p>
<p>如此一来，假设每部 web server 的「同时联机数」都是 200，而且同时使用 2 部 web server 会怎么样呢？从 web1 来了 50 个「顾客」，先是到 DB1 走一趟，接着再到 DB2 晃一圈，这样需要多少「服务生」接待他们？100 个（web1-&gt;DB1: 50　web1-&gt;DB2: 50）！又从 web2 来了 50 个「顾客」，也做了同样的动作（web2-&gt;DB1: 50　web2-&gt;DB2: 50）。在此之后，还有「服务生」是闲着的吗？后续若从 web1 或 web2 同时涌入多于 50 位「顾客」时，谁来应付他们？</p>
<p>倘若您使用的是像 Apache 这类的 multi-process web server（一个 parent process 协调一组 children processes 运作），某个 children process 建立的「持续联机」，是不能分享给其它 children process 来使用的（「服务生」只对先前接待过的「顾客」服务）。在这样的情况下，将会使得 MySQL 上闲置的 process 越积越多（很多「服务生」站在门口等着「老顾客」上门，而不理会「新顾客」）。<br />
mysql_pconnect( ) 一定是最佳选择吗？我想未必尽然。<br />
——– 两者之间的区别 ————–<br />
mysql_pconnect() 和 mysql_connect() 非常相似，但有两个主要区别。<br />
首先，当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接</p>
<p>标识而不打开新连接。<br />
其次，当脚本执行完毕后到 SQL 服务器的连接不会被关闭，此连接将保持打开以备以后使用（mysql_close() 不会关闭由</p>
<p>mysql_pconnect() 建立的连接）。<br />
可选参数 client_flags 自 PHP 4.3.0 版起可用。<br />
此种连接称为”持久的”。<br />
看到这里，写一条代码来测试一下</p>
<div style="background-color: #f9fbfc; border: 1px solid #c3ced9; margin: 0px; width: auto; height: auto; overflow: auto; text-align: left;">
<div style="padding: 6px 24px; margin: 0px; line-height: 15px; background-color: transparent;"><span style="color: #ffa500;">/*<br />
* pconnect_test.php<br />
*/</span><span style="color: gray;"><br />
</span><span style="color: #00008b;">$link</span><span style="color: gray;"><span> </span>=<span> </span></span><span style="color: blue;">mysql_pconnect</span><span style="color: olive;">(</span><span style="color: #8b0000;">"</span><span style="color: red;">localhost</span><span style="color: #8b0000;">"</span><span style="color: gray;">,<span> </span></span><span style="color: #8b0000;">"</span><span style="color: red;">mysql_user</span><span style="color: #8b0000;">"</span><span style="color: gray;">,<span> </span></span><span style="color: #8b0000;">"</span><span style="color: red;">mysql_password</span><span style="color: #8b0000;">"</span><span style="color: olive;">)</span><span style="color: gray;"><br />
</span><span style="color: green;">or</span><span style="color: gray;"><span> </span></span><span style="color: green;">die</span><span style="color: olive;">(</span><span style="color: #8b0000;">"</span><span style="color: red;">Could not connect:<span> </span></span><span style="color: #8b0000;">"</span><span style="color: gray;"><span> </span>.<span> </span></span><span style="color: blue;">mysql_error</span><span style="color: olive;">())</span><span style="color: gray;">;<br />
</span><span style="color: blue;">print</span><span style="color: gray;"><span> </span></span><span style="color: olive;">(</span><span style="color: #8b0000;">"</span><span style="color: red;">Connected successfully</span><span style="color: #8b0000;">"</span><span style="color: olive;">)</span><span style="color: gray;">;</span></div>
</div>
<p>通过刷新网页的方式执行这条代码，发现每执行一次，mysql的进程数就增加一个。在这里我不禁有了疑问。上面说mysql_pconnect这个函</p>
<p>数的使用的时候，不是说”当连接的时候本函数将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到</p>
<p>，则返回此标识而不打开新连接”么？为什么我每刷新一次页面他就给我打开一个新的连接呢？</p>
<p>考虑到这有可能是PHP的bug，我到PHP的bug列表中找关于和too many connections 有关的条目。<br />
相关的话题主要有三个，分别是</p>
<div style="background-color: #f9fbfc; border: 1px solid #c3ced9; margin: 0px; width: auto; height: auto; overflow: auto; text-align: left;">
<div style="padding: 6px 24px; margin: 0px; line-height: 15px; background-color: transparent;"><span style="color: #ffa500;">#11966        mysql_pconnect opens new connections with the same parameters</span><span style="color: gray;"><br />
</span><span style="color: #ffa500;">#26117        Persistent connection not reused</span><span style="color: gray;"><br />
</span><span style="color: #ffa500;">#13589        Persistent connections stay open and accumulate</span></div>
</div>
<p>描述比较长,我就不在这里贴,具体的内容你自己去看。重点主要是”当一个进程打开一个mysql的持续连接，只要该进程还存在，这个持续</p>
<p>的连接就不会断开，而且每一个进程会打开一个mysql的持续连接，而不能使用其他进程打开的持续连接”。</p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/638/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL IN 条件语句 排序</title>
		<link>http://www.leakon.com/archives/636</link>
		<comments>http://www.leakon.com/archives/636#comments</comments>
		<pubDate>Sat, 08 May 2010 06:10:50 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=636</guid>
		<description><![CDATA[有个场景，一个几万条记录的表，主键是 id，我想从表中取 id 为 30，20，80，40 的几条记录。
注意，30，20，80，40，是我预期的顺序，我希望 MySQL 按这样的顺序返回记录。
于是我这样写 SQL：
SELECT * FROM my_table WHERE id IN (30, 20, 80, 40);
结果是，他没有按我给的顺序返回。
怎么办？
查到了 FIELD() 函数。
FIELD(str,str1,str2,str3,...)
Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found.
把 SQL 语句改写为：
SELECT * FROM my_table WHERE id IN (30, 20, 80, 40) ORDER BY FIELD(id, [...]]]></description>
			<content:encoded><![CDATA[<p>有个场景，一个几万条记录的表，主键是 id，我想从表中取 id 为 30，20，80，40 的几条记录。</p>
<p>注意，30，20，80，40，是我预期的顺序，我希望 MySQL 按这样的顺序返回记录。</p>
<p>于是我这样写 SQL：</p>
<p>SELECT * FROM my_table WHERE id IN (30, 20, 80, 40);</p>
<p>结果是，他没有按我给的顺序返回。</p>
<p>怎么办？</p>
<p>查到了 FIELD() 函数。</p>
<p>FIELD(str,str1,str2,str3,...)<br />
Returns the index (position) of str in the str1, str2, str3, ... list. Returns 0 if str is not found.</p>
<p>把 SQL 语句改写为：</p>
<p>SELECT * FROM my_table WHERE id IN (30, 20, 80, 40) ORDER BY FIELD(id, 30, 20, 80, 40);</p>
<p>排序过程是：</p>
<p>把选出的记录的 id 在 FIELD 列表中进行查找，并返回位置，以位置作为排序依据。</p>
<p>这样的用法，会导致 Using filesort，是效率很低的排序方式。除非数据变化频率很低，或者有长时间的缓存，否则不建议用这样的方式排序。</p>
<p>把 MySQL 返回的结果，用 PHP 在内存中按 id 顺序重新排列，是个不错的优化方案。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/636/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sudo: sorry, you must have a tty to run sudo</title>
		<link>http://www.leakon.com/archives/634</link>
		<comments>http://www.leakon.com/archives/634#comments</comments>
		<pubDate>Sat, 03 Apr 2010 04:06:18 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Sudo]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=634</guid>
		<description><![CDATA[I was recently working on a Perl script that would SSH to another server and run a sudo command on the remote server that was failing. The error that was received is below.
Error: sudo: sorry, you must have a tty to run sudo
The reason for this is an update along the way with sudo locked [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently working on a Perl script that would SSH to another server and run a sudo command on the remote server that was failing. The error that was received is below.</p>
<p><strong>Error: sudo: sorry, you must have a tty to run sudo</strong></p>
<p>The reason for this is an update along the way with sudo locked it down further by adding the below line to /etc/sudoers configuration file.</p>
<pre>Defaults requiretty</pre>
<p>To allow a remote script to login and run a command via sudo simply comment out that line as shown below.</p>
<pre># Commented out so remote script can login and run a command without a tty
# Defaults requiretty</pre>
<p>I would suggest making a comment in the sudoers file along with the actual script that is running just in case there is another systems administrator that is tasked with working on this server at a later date. Now when your script runs it will not throw that error and should be able to run the remote command that was initially required.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/634/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL 索引优化</title>
		<link>http://www.leakon.com/archives/631</link>
		<comments>http://www.leakon.com/archives/631#comments</comments>
		<pubDate>Wed, 24 Mar 2010 00:10:53 +0000</pubDate>
		<dc:creator>leakon</dc:creator>
				<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.leakon.com/?p=631</guid>
		<description><![CDATA[表中包含 10 万条记录，有一个 datetime 类型的字段。
取数据的语句：
SELECT * FROM my_table WHERE created_at &#60; '2010-01-20';
用 EXPLAIN 检查，发现 type 是 ALL， key 是 NULL，根本没用上索引。
可以确定的是，created_at 字段设定索引了。
什么原因呢？
用 SELECT COUNT(*) 看了一下符合 WHERE 条件的记录总数，居然是 6W 多条！！
难怪不用索引，这时用索引毫无意义，就好像 10 万条记录的用户表，有个性别字段，不是男就是女，在这种字段设置索引是错误的决定。
稍微改造一下上述语句：
SELECT * FROM my_table WHERE created_at BETWEEN '2009-12-06' AND '2010-01-20';
这回问题解决！
符合条件的记录只有几百条，EXPLAIN 的 type 是 range，key 是 created_at，Extra 是 Using where 。
自己总结个准则，索引的目的就是尽量缩小结果集，这样才能做到快速查询。
]]></description>
			<content:encoded><![CDATA[<p>表中包含 10 万条记录，有一个 datetime 类型的字段。</p>
<p>取数据的语句：</p>
<pre>SELECT * FROM my_table WHERE created_at &lt; '2010-01-20';</pre>
<p>用 EXPLAIN 检查，发现 type 是 ALL， key 是 NULL，根本没用上索引。</p>
<p>可以确定的是，created_at 字段设定索引了。</p>
<p>什么原因呢？</p>
<p>用 SELECT COUNT(*) 看了一下符合 WHERE 条件的记录总数，居然是 6W 多条！！</p>
<p>难怪不用索引，这时用索引毫无意义，就好像 10 万条记录的用户表，有个性别字段，不是男就是女，在这种字段设置索引是错误的决定。</p>
<p>稍微改造一下上述语句：</p>
<pre>SELECT * FROM my_table WHERE created_at BETWEEN '2009-12-06' AND '2010-01-20';</pre>
<p>这回问题解决！</p>
<p>符合条件的记录只有几百条，EXPLAIN 的 type 是 range，key 是 created_at，Extra 是 Using where 。</p>
<p>自己总结个准则，索引的目的就是尽量缩小结果集，这样才能做到快速查询。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leakon.com/archives/631/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
