0

这是我们用来调用 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)
})();
4

1 回答 1

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
}
于 2013-02-20T04:18:22.813 回答