如果有可能触发iframe的onload事件?,因为我的要求我需要在iframe中加载外部网站。即使有些网站不允许在iframe中加载他们的网页
例如:https://www.google.co.in,我需要验证网址是否有效加载iframe。任何人都建议我解决?
答案 0 :(得分:0)
试试这段代码:
if (iframe.attachEvent){
iframe.attachEvent("onload", function(){
alert("Local iframe is now loaded."(www.111cn.net));
});
} else {
iframe.onload = function(){
alert("Local iframe is now loaded.");
};
}
答案 1 :(得分:0)
检查一下,创建一个间隔以检查元素是否准备好
var element = document;
var eventName = "load";
var handShake = element.attachEvent || element.addEventListener;
eventName = (handShake.toString().indexOf("add") === -1) ? "on" + eventName : eventName;
handShake(eventName, function () {
this.setAttribute("data-loaded", "true");
});
// to check if is loaded
if(element.dataset.loaded === "true"){
// do things
}