使用Onbody的iframe异步延迟

时间:2018-12-19 16:35:43

标签: javascript iframe

我要先加载页面,然后再加载iframe。问题是在某些页面上有两个不同的iframe来源(外部)。我了解body unload是实现这一目标的方法。

对于多个iframe,我需要对代码的哪一部分进行更改?

我的代码如下:

  //doesn't block the load event
function createIframe() {
    var i = document.createElement("iframe");
    i.src = "https://thetaphunter.appspot.com/widgets/locationWidget?orderby=style&style=on&breweryname=on&format=images&brewerylocation=on&servingtype=both&updatedate=on&location=The-Hangout-Restaurant-and-Beach-Bar";
    i.scrolling = "auto";
    i.frameborder = "0";
    i.width = "90%";
    i.height = "220px";
    document.getElementById("map").appendChild(i);
};

// Check for browser support of event handling capability
if (window.addEventListener) window.addEventListener("load", createIframe, false);
else if (window.attachEvent) window.attachEvent("onload", createIframe);
else window.onload = createIframe;

View Fiddle

0 个答案:

没有答案