{"id":342,"date":"2006-05-20T11:31:11","date_gmt":"2006-05-20T17:31:11","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=342"},"modified":"2006-05-20T11:31:11","modified_gmt":"2006-05-20T17:31:11","slug":"verifying-the-state-of-an-image-download-in-an-javascript-event","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/342","title":{"rendered":"Verifying the state of an image download in an javascript event"},"content":{"rendered":"<p>Well, I was going to write a rant, explaining how as far as I could tell, there was no way to make sure an image was downloaded, or degrade gracefully if it wasn&#8217;t&#8211;within an event like onclick.  But, it all boils down to the fact that there is  no <code>Thread.sleep()<\/code> equivalent in javascript.  See <a href='http:\/\/www.faqts.com\/knowledge_base\/view.phtml\/aid\/1602\/fid\/143'>this for a fine explication<\/a> or read on for an overview of what I tried that failed.<\/p>\n<p>The problem is that the only real way to do it in javascript is to use <code>setTimeout<\/code> (<a href='http:\/\/developer.mozilla.org\/en\/docs\/DOM:window.setTimeout'>Mozilla docs<\/a>, <a href='http:\/\/msdn.microsoft.com\/workshop\/author\/dhtml\/reference\/methods\/setTimeout.asp'>IE docs<\/a>). The problem with <code>setTimeout<\/code> is that after calling it, your event handling code merrily continues to execute, and that your <code>setTimeout<\/code> callback will probably not finish before the event code is finished.  <\/p>\n<p>The other way I thought of was to loop waiting for a specified number of seconds (like <a href='http:\/\/codewalkers.com\/archives\/clientside\/584.html'>this<\/a>).  Unfortunately, in my tests, the javascript engine in IE6 doesn&#8217;t appear to be multithreaded, and while this wait code executes, the image is not being downloaded.<\/p>\n<p>I did not try the modal window approach, or the java applet (which seems a bit like using a sledgehammer to hit a mosquito) outlined <a href='http:\/\/www.faqts.com\/knowledge_base\/view.phtml\/aid\/1602\/fid\/143'>here<\/a>, but I&#8217;m not sure that either of those is really production ready (<a href='http:\/\/ajaxpatterns.org\/Scheduling'>I&#8217;m not alone<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well, I was going to write a rant, explaining how as far as I could tell, there was no way to make sure an image was downloaded, or degrade gracefully [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-342","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=342"}],"version-history":[{"count":0,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/342\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=342"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=342"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}