首页 > 解决方案 > 当用户单击“在新选项卡中打开”时,如何重定向 iframe 内的链接?

问题描述

我正在开发一个让用户使用一堆服务(火花等)的网络应用程序。当用户选择启动服务时,比如 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}}/{{page }}?

谢谢,对不起,如果我不清楚。

标签: javascriptpythonhtmlweb

解决方案


<a href="..." target="_top">My Link</a>在框架链接中使用


推荐阅读