简体   繁体   English

是否有可能从 html 页面中的“iframe”触发“onload”事件

[英]Is there any possibilities to get fired 'onload' event from 'iframe' in a html page

If there any possible way to fire onload event of iframe ?, Because for my requirement I need to load external websites in iframe.如果有任何可能的方法来触发 iframe 的 onload 事件?,因为对于我的要求,我需要在 iframe 中加载外部网站。 Even though some of the sites not allowing to load their pages in iframe即使一些网站不允许在 iframe 中加载他们的页面

Eg: https://www.google.co.in , I need to validate the url whether that's valid to load in iframe or not.例如: https://www.google.co.in ,我需要验证 url 是否可以在 iframe 中加载。 could any one suggest me to resolve?任何人都可以建议我解决吗?

try this code : 试试这个代码:

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.");
     };
 }

Check this out, create a interval to check if the element is ready 检查一下,创建一个间隔来检查元素是否准备好

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
}

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

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