首页 文章

在新窗口/标签中打开Google文档iframe链接无法在Internet Explorer中使用

提问于
浏览
0

我在我的html页面中嵌入了iframe,该页面链接到Google Doc . 但是,使用Internet Explorer时,会在iframe中打开链接 . 我想要在新窗口或新标签中打开链接 .

我已经搜索了这个问题的答案,并找到了以下代码,但它在Internet Explorer或Edge中不起作用,显然是因为IE无法识别srcdoc

有谁知道跨浏览器解决方案?

<script src="js/jquery-1.8.3.min.js"></script>

<iframe srcdoc="" frameborder="0" scrolling="no"  style="height:1000px; width:100%"></iframe>

<script>
    $(function() {
        $.get("https://docs.google.com/document/d/1fwt5APDmopqJ6R3aAzg_WCJBhbju1l03DtiSWNbYntg/pub?embedded=true", function(html) {
        var contents = $("iframe").contents();

        contents.find("html").html(html);

        setTimeout(function() {
            contents.find('a[href^="http://"]').attr("target", "_blank");
            contents.find('a[href^="https://"]').attr("target", "_blank");
        }, 1000); 
    });
});

1 回答

  • 0

    哇!我想我找到了解决方案

    在上面的代码中,只需将srcdoc =“”更改为src =“”,它就可以在IE中运行

    谁能证实这个解决方案是安全的?我不想打破互联网!

相关问题