<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[js detect image 404，read the HTTP header to check for 404 with jQuery without performing an ajax request]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Mon, 24 Mar 2014 10:02:34 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	js detect image 404：<br/>一、用Ajax，代码量较长：<br/><textarea name="code" class="php" rows="15" cols="100">
// http://jsfiddle.net/SRvqN/1/
$(window).load(function() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;$(&#039;img&#039;).each(function() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var url = $(this).attr(&quot;src&quot;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$.ajax(url, &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cache: true,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;statusCode: &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;404 : function() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$(&#039;table&#039;).append(&#039;&lt;tr&gt;&lt;td&gt;&#039; + url + &#039;&lt;/td&gt;&lt;/tr&gt;&#039;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#125;);
&nbsp;&nbsp;&nbsp;&nbsp;&#125;);
&#125;);
 </textarea><br/>二、用图像的onerror函数实现判断404，实践OK：<br/>_________________________________________________________________________<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;script type=&quot;text/javascript&quot;&gt;
window.onload = window_load;

function window_load()
&nbsp;&nbsp; &#123;
&nbsp;&nbsp; var img1 = new Image();
&nbsp;&nbsp; img1.onload = function () &#123; alert( &#039;1 LOADED&#039; ); &#125;;
&nbsp;&nbsp; img1.onerror = function () &#123; alert( &#039;1 ERROR&#039; ); &#125;;
&nbsp;&nbsp; img1.src = &#039;http://yourdomain.net/images/onethatdoesnotexist.gif&#039;;

&nbsp;&nbsp; var img2 = new Image();
&nbsp;&nbsp; img2.onload = function () &#123; alert( &#039;2 LOADED&#039; ); &#125;;
&nbsp;&nbsp; img2.onerror = function () &#123; alert( &#039;2 ERROR&#039; ); &#125;;
&nbsp;&nbsp; img2.src = &#039;http://yourdomain.net/images/onethatdoesexist.gif&#039;;
&nbsp;&nbsp; &#125;

&lt;/script&gt;
</textarea><br/><br/>来自：http://forums.mozillazine.org/viewtopic.php?f=25&amp;t=315570<br/><br/><textarea name="code" class="php" rows="15" cols="100">
function UrlExists(url) &#123;
&nbsp;&nbsp;var http = new XMLHttpRequest();
&nbsp;&nbsp;http.open(&#039;HEAD&#039;, url, false);
&nbsp;&nbsp;http.send();
&nbsp;&nbsp;return http.status != 404;
&#125;


var threshold&nbsp;&nbsp; = 500,
&nbsp;&nbsp;&nbsp;&nbsp;successFunc = function()&#123; console.log(&#039;It exists!&#039;); &#125;;

var myXHR = $.ajax(&#123;
&nbsp;&nbsp;url: $(&#039;#checkme&#039;).attr(&#039;href&#039;),
&nbsp;&nbsp;type: &#039;text&#039;,
&nbsp;&nbsp;method: &#039;get&#039;,
&nbsp;&nbsp;error: function() &#123;
&nbsp;&nbsp;&nbsp;&nbsp;console.log(&#039;file does not exist&#039;);
&nbsp;&nbsp;&#125;,
&nbsp;&nbsp;success: successFunc
&#125;);

setTimeout(function()&#123;
&nbsp;&nbsp;myXHR.abort();
&nbsp;&nbsp;successFunc();
&#125;, threshold);
</textarea><br/><br/>Hello All, <br/><br/>can do this either by Jquery or Javascript... <br/><textarea name="code" class="php" rows="15" cols="100">
This is what i have done so far... 
function checkURL(url) &#123; 
var urlregex = new RegExp(&quot;^(http&#124;https&#124;ftp)&#92;://([a-zA-Z0-9&#92;.&#92;-]+(&#92;:[a-zA-Z0-9&#92;.&amp;%&#92;$&#92;-]+)*@)*((25[0-5]&#124;2[0-4][0-9]&#124;[0-1]&#123;1&#125;[0-9]&#123;2&#125;&#124;[1-9]&#123;1&#125;[0-9]&#123;1&#125;&#124;[1-9])&#92;.(25[0-5]&#124;2[0-4][0-9]&#124;[0-1]&#123;1&#125;[0-9]&#123;2&#125;&#124;[1-9]&#123;1&#125;[0-9]&#123;1&#125;&#124;[1-9]&#124;0)&#92;.(25[0-5]&#124;2[0-4][0-9]&#124;[0-1]&#123;1&#125;[0-9]&#123;2&#125;&#124;[1-9]&#123;1&#125;[0-9]&#123;1&#125;&#124;[1-9]&#124;0)&#92;.(25[0-5]&#124;2[0-4][0-9]&#124;[0-1]&#123;1&#125;[0-9]&#123;2&#125;&#124;[1-9]&#123;1&#125;[0-9]&#123;1&#125;&#124;[0-9])&#124;([a-zA-Z0-9&#92;-]+&#92;.)*[a-zA-Z0-9&#92;-]+&#92;.(com&#124;edu&#124;gov&#124;int&#124;mil&#124;net&#124;org&#124;biz&#124;arpa&#124;info&#124;name&#124;pro&#124;aero&#124;coop&#124;museum&#124;[a-zA-Z]&#123;2&#125;))(&#92;:[0-9]+)*(/($&#124;[a-zA-Z0-9&#92;.&#92;,&#92;?&#92;&#039;&#92;&#92;&#92;+&amp;%&#92;$#&#92;=~_&#92;-]+))*$&quot;); 
if (urlregex.test(value)) &#123; 
alert(&quot;valid url&quot;); 
var request = new XMLHttpRequest; 
request.open(&#039;GET&#039;, url, false); 

request.onreadystatechange = function()&#123; 
if(request.readyState==4)&#123; 
console.log(request.readyState); 
return true; 
&#125;else&#123; 
return false; 
&#125; 
&#125; 
request.send(); 
&#125; 
alert(&quot;invalida url pattern&quot;); 
return (false); 
&#125; 
</textarea><br/><br/>来自：<br/>http://www.coderanch.com/t/624410/HTML-CSS-JavaScript/check-url-returns-error-status
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] js detect image 404，read the HTTP header to check for 404 with jQuery without performing an ajax request]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>