【问题标题】:How to redirect links inside iframe when users clicks "open in a new tab"?当用户单击“在新选项卡中打开”时,如何重定向 iframe 内的链接?
【发布时间】:2019-06-01 23:33:46
【问题描述】:

我正在开发一个允许用户使用大量服务(spark 等)的网络应用程序。 当用户选择启动服务时,比如 Spark,应用程序将打开一个新选项卡,其中将包含我的页面(service.html),其中包含有关用户的一些信息,然后是 iframe,如下所示:

 <table width="100%" style="padding: 0px;">
            <tr>
                <td align="right" style="padding: 0px;">
                    <i class="fa fa-wifi" style="color:gray;"> {{ some stuff}}</i>
                </td>
            </tr>
  </table>
  <iframe id="serviceIframe" width="100%" height="100%" frameborder="0" src="http://localhost:{{port}}/{{page}}" target="_self"/>

一切正常,但我的问题是,如果用户在 iframe 中的任何链接上单击“在新选项卡中打开”,它将转到 http://localhost:{{port}}/{{page}} ,而不是服务 html,我想在服务旁边显示的内容将会丢失。

我该怎么做,当用户点击 iframe 内链接上的“在新标签页中打开”时,它会重定向到我的 service.html 页面,而不是 http://localhost:{{port}}/{{页}}?

如果我不清楚,谢谢和抱歉。

【问题讨论】:

    标签: javascript python html web


    【解决方案1】:

    在框架链接中使用&lt;a href="..." target="_top"&gt;My Link&lt;/a&gt;

    【讨论】:

    • 我认为跨域策略阻止我修改 iframe 的内容。还有其他解决办法吗?
    • 你不能用javascript修改iframe的内容。不能直接改iframe资源代码就没办法
    • 感谢您的回复!
    猜你喜欢
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    • 2014-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多