简体   繁体   English

使用jQuery UI对话框iframe显示onload

[英]showing onload with jquery ui dialog iframe ie

i am looking for suggestions/workarounds or better ways to do this This little bit of code works for FF and chrome but hideProgress does not get called in IE 我正在寻找建议/解决方法或更好的方法来执行此操作这一点代码适用于FF和chrome,但hideProgress不会在IE中调用

function showPDF(url){
       $("#divId")
               .html('<div id="loading">Loading....</div>
                      <iframe id="modalIframeId" width="100%" height="100%" 
                          src='+url+' marginWidth="0" marginHeight="0" frameBorder="0"
                          scrolling="auto" title="Dialog Title" 
                      onload="hideProgress();">Your browser does not support</iframe>')
               .dialog('open');
        return ;
   }
   function hideProgress(){
       $('#loading').hide();
   }

Thanks for any help 谢谢你的帮助

Try assigning the onload event handler call to #modalIframeId with the .on() or .delegate() function instead of placing it into the <iframe> tag you're inserting. 尝试使用.on().delegate()函数将onload事件处理程序调用分配给#modalIframeId,而不是将其放入要插入的<iframe>标记中。 I'm surprised it works in FF and Chrome - most of the time, assigning an event handler like that with any dynamic piece of code doesn't work because of how jQuery interacts with the code of the page. 令我惊讶的是,它在FF和Chrome中都能正常工作-在大多数情况下,由于jQuery如何与页面代码交互,因此无法为任何动态代码分配这样的事件处理程序。 You may also want to experiment with having a unique id for the #modalIframeId iframe - If you were to call the showPDF() function more than once on a page, it would create elements with duplicate id's and that confuses jQuery and produces unexpected results. 您可能还想尝试使用#modalIframeId iframe的唯一ID-如果要在页面上多次调用showPDF()函数,它将创建具有重复ID的元素,这会混淆jQuery并产生意外结果。 in my experience, even if you remove #modalIframeId and then re-add it, it may still cause problems. 以我的经验,即使删除#modalIframeId然后重新添加,它仍然可能会引起问题。 A unique id each time you create it prevents this potential problem. 每次创建唯一ID都可以避免此潜在问题。

As the previous answer mentioned the issue here is the fact that you are attaching the event handler inline. 正如前面的答案所提到的,这里的问题是您要内联附加事件处理程序。 The functionality you're looking for can be achieved by simply breaking up your function. 您所需的功能可以通过简单地分解功能来实现。 I've demonstrated this in this jsFiddle: 我已经在jsFiddle中演示了这一点:

http://jsfiddle.net/xyctR/2/ http://jsfiddle.net/xyctR/2/

'loaded' is logged in all browsers. “已加载”已记录在所有浏览器中。

Furthermore, passing 'open' to jQuery UI's dialog method is unnecessary in this case. 此外,在这种情况下,不需要将“ open”传递给jQuery UI的dialog方法。 Just call dialog() . 只需调用dialog()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM