博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

ios safari (cached) image onload not fired

Posted on 2014-04-03 18:12  bw_0927  阅读(1775)  评论(0)    收藏  举报

http://ajaxian.com/archives/safari-3-onload-firing-and-bad-timing

 

Regarding images, Safari does wait until the image data has been fetched before firing onload, but it does not decode images until they actually paint. Again this is common sense to keep memory usage down (and is especially useful on mobile devices). Most other browsers are not very smart in this respect and aggressively decode images before firing the onload. This is neither necessary nor required to be compliant with onload (and it wastes memory and hurts performance).

 

 

http://stackoverflow.com/questions/19451353/html-jquery-onload-load-not-getting-executed-on-ios

 

So I ended up being able to make the load method execute. I switched my code to use imagesLoaded(http://desandro.github.io/imagesloaded/), but that still did not fix my issue. It seems that in Mobile Safari, it doesn't load objects that aren't added to the DOM. Once I added my dynamically generated images to a div, it started working. I'm not sure if that was by design from Apple for memory purposes, or just an issue.

Thought I'd post this to help somebody else who might run into this problem.

var $img = $('<img>').attr('src', files[i]).css({"position":"absolute","top":"0px","left":"0px",).prependTo(".canvas").imagesLoaded(function(){
                    drawLayersWhenAllAreLoaded();});

http://mike-donaldson.com/tips-and-tricks/jquery-load-event-not-firing-on-images/

$('.imageSelector').load(function(){  

  //Do Something...

}).each(function(){

    if(this.complete) {

      $(this).trigger('load');

  }

});

 
======================
最后经测试所有这些问题在ios7.1上都不存在,
对于CITRIX html5代码中.load事件无法在ios上被触发的原因是用 window.opeon()打开了一个新窗口导致的
window.open();
var newImg = new Image();
newImg.onload = funciont()
{
  alert("loaded");
}
newImg.src = "./somePig.png"

http://www.barrelny.com/blog/taking-control-of-imageloading/