iframe中的onload不起作用,如果iframe在src中有非html文档(pdf或文本) [英] onload in iframes not working, if iframe have non-html document in src (pdf or text)

查看:1920
本文介绍了iframe中的onload不起作用,如果iframe在src中有非html文档(pdf或文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有iframe和onload处理程序:

I have iframe with onload handler:

<iframe id="FrameForPrintVersion" src="" border="0" style="height:0; width:0; visibility:hidden;" onload = 'frameOnload()' >

如果我使用html-pages作为iframe的来源,它可以正常工作,但是当我设置src到任何pdf文档。
在这种情况下加载PDF文档时是否可以处理?

It works fine if i use html-pages as the source of the iframe, but not when i set src to any pdf document. Is it posible to handle when a PDF document was loaded in this case?

推荐答案

根据W3C,iframe标记不支持任何事件属性。
虽然主流浏览器支持但不能依赖它。
如果你真的想要它尝试这种解决方法。你可以尝试这样的事情。

According to the W3C, the iframe tag does not support any event attributes. Although major browsers support it but can not be relied upon. If you really want it try this workaround.You can try something like this.

setTimeout(function(){
    if($('#FrameForPrintVersion').contents().find('*')!='undefined') {
        alert('your frame loaded');
    }
},200)

这篇关于iframe中的onload不起作用,如果iframe在src中有非html文档(pdf或文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆