我需要在Angular App中显示几个iframe。
为此,我的HTML就像
<iframe ng-src="{{iframeObj.iUrl}}" frameborder="0"></iframe>
但是当iframes中不允许使用iUrl时X-Frame-Options:SAMEORIGIN或DENY
然后我的IFrame没有来,并且很自然它不会来。
但我想在Iframe无法正确加载时显示替代文字。像Image tag has和alt属性。
当iframe无法加载时,我需要一些方法来显示替代文字。
最需要AngularJS和普通的JavaScript解决方案。
提前致谢。
答案 0 :(得分:0)
我找到了解决问题的方法:
我们的想法是设置onload
事件之前设置src。
您可以尝试以下代码:
document.getElementsByTagName('iframe').onload=function(){
try{
var win=this.contentWindow;
win.closed && error_function();
}catch(e){
error_function();
}
};
点击此处查看其工作原理:http://jsfiddle.net/tec6y2y9/1/
注意:在小提琴上,我做了一些更改,以表明它确实有效!
error_function()
是一个虚构的函数,用于显示代码在发生故障时的位置!
我希望这适合你。