google chrome - javascript check if image is in browser cache -


i have following code check if external image cached or not

<script type="text/javascript">     function cached(url){        var test = document.createelement("img");        test.src = url;        return test.complete || test.width+test.height > 0;     }     var base_url = "http://www.google.com/images/srpr/nav_logo80.png"     alert("expected: true or false\n" +         cached(base_url)         + "\n\nexpected: false (cache-busting enabled)\n" +         cached(base_url + "?" + new date().gettime()));          </script> 

i following result false false, true false on firefox , ie (which assume first fires false false,then after grabs image, fires true,false, in chrome false, false always

any reason why?

the answer on this question seems work on chrome.

function cached(url){     var test = document.createelement("img");     test.src = url;     return test.complete || test.width+test.height > 0; } var base_url = "http://www.google.com/images/srpr/nav_logo80.png" alert("expected: true or false\n" +   cached(base_url)   + "\n\nexpected: false (cache-busting enabled)\n" +   cached(base_url + "?" + new date().gettime())); 

answer copy/pasted question, not work.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -