【问题标题】:Open Google Docs iframe link in new window/tab not working in Internet Explorer在新窗口/标签中打开 Google Docs iframe 链接在 Internet Explorer 中不起作用
【发布时间】:2016-03-20 02:17:35
【问题描述】:

我在我的 html 页面中嵌入了一个链接到 Google Doc 的 iframe。但是,在使用 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); 
    });
});

【问题讨论】:

    标签: jquery internet-explorer iframe hyperlink


    【解决方案1】:

    哇!我想我找到了解决办法

    在上面的代码中,只需将 srcdoc="" 改为 src="" 即可在 IE 中运行

    谁能确认这个解决方案是安全的?我不想破坏互联网!

    【讨论】:

      猜你喜欢
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-30
      • 2014-12-12
      • 2011-06-02
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多