我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
当前回答
我找到了一个简单的解决办法
<iframe class="embedded-content" sandbox="allow-top-navigation"></iframe>
allow-top-navigation 允许iframe更改parent.location。 更多信息https://javascript.info/cross-window-communication
其他回答
使用目标属性:
<a target="_parent" href="http://url.org">link</a>
使用JavaScript:
window.parent.location.href= "http://www.google.com";
试目标= " _top "
<a href="http://example.com" target="_top">
This link will open in same but parent window of iframe.
</a>
尝试在锚标记内的target="_parent"属性。
我发现最好的解决方案是使用基本标签。在iframe的页面头部添加以下内容:
<base target="_parent">
这将在父窗口中加载页面上的所有链接。如果你想要你的链接加载在一个新的窗口,使用:
<base target="_blank">
浏览器支持