Strange jQuery $(window).load() behavior in Safari

做~自己de王妃 提交于 2019-12-12 09:47:51

问题


I have a page being loaded in an <iframe>.

Inside the <iframe>, I have a function that patiently waits for the page to load using jQuery's $(window).load() event which is supposed to wait until ALL page content (images, javascript, css, etc.) is loaded before firing.

The function then calls back to the page loading the <iframe> using postMessage to send the height of the content in the <iframe> back.

I have tested the functionality in IE7, IE8, Firefox 2, Firefox 3, Opera, and Chrome and everything works fine. When I try to load the page in Safari, the function makes its call back before images are loaded...thus giving me the wrong page height.

Does anybody out there know how to force Safari to wait for images to be loaded before calling a function (jQuery solutions are preferable in this case)?


回答1:


Checking for an offset forces safari for finish loading/layout out the content, it blocks javascript until the return completes. You can use it like this:

$(window).load(function() {
  var block = document.body.offsetWidth;
  //Rest of code...
});


来源:https://stackoverflow.com/questions/2526315/strange-jquery-window-load-behavior-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!