【问题标题】:This javascript gets the iFrame to load on a page. It won't load in IE...此 javascript 获取 iFrame 以加载到页面上。它不会在IE中加载...
【发布时间】:2013-02-20 03:52:10
【问题描述】:

这是我们用来调用 iframe 的 js。在 IE 中,它要么超时要么得到一个“ Internet Explorer 无法加载页面”消息。它在 Chrome 和 Firefox 中运行良好。任何见解都将不胜感激......

(function () {
    function f(i) {
        if (i.origin !== e + "" + n) {
            return
        }
        if (i.data === "destroy_bookmarklet") {
            var s = document.getElementById(g);
            if (s) {
                document.body.removeChild(s);
                s = null
            }
        }
    }
    var e = "http://",
        n = "URL GOES HERE",
        g = "ID_div",
        r = "ID_content_iframe",
        i = document.getElementById(r);
    if (i) {
        return
    }
    var d = document.createElement("div"),
        s = e + "" + n + "/post/create?response_type=embed",
        o = document.createElement("iframe");
    d.id = g;
    d.style.position = "absolute";
    d.style.top = "0";
    d.style.left = "0";
    d.style.height = "100%";
    d.style.width = "100%";
    d.style.zIndex = "16777270";
    o.id = r;
    o.src = s + "&link=" + encodeURIComponent(window.location.href) + "&title=" + encodeURIComponent(document.title) + "&description=" + encodeURIComponent("" + (window.getSelection ? window.getSelection() : document.getSelection ? document.getSelection() : document.selection.createRange().text));
    o.style.height = "600px";
    o.style.width = "650px";
    o.style.border = "10px solid #333333";
    o.style.marginTop = "100px";
    o.style.marginLeft = "auto";
    o.style.marginRight = "auto";
    o.style.display = "block";
    o.style.background = "#ffffff";
    o.style.overflowY = 'scroll';
    o.style.overflowX = 'hidden';
    document.body.appendChild(d);
    d.appendChild(o);
    var u = window.addEventListener ? "addEventListener" : "attachEvent";
    var a = u == "attachEvent" ? "onmessage" : "message";
    window[u](a, f, false)
})();

【问题讨论】:

  • window.window[u](a, f, false);?

标签: javascript internet-explorer iframe internet-explorer-8 internet-explorer-9


【解决方案1】:
if (el.addEventListener){
  el.addEventListener('your function', yourtext, false); //this is for IE 9 to above
} else if (el.attachEvent){
  el.attachEvent('your function', yourtext);//this is for IE 9 to lower
}

【讨论】:

    猜你喜欢
    • 2011-08-17
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-05
    • 2015-06-01
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多