我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
当前回答
我找到了一个简单的解决办法
<iframe class="embedded-content" sandbox="allow-top-navigation"></iframe>
allow-top-navigation 允许iframe更改parent.location。 更多信息https://javascript.info/cross-window-communication
其他回答
试目标= " _top "
<a href="http://example.com" target="_top">
This link will open in same but parent window of iframe.
</a>
使用目标属性:
<a target="_parent" href="http://url.org">link</a>
有一个HTML元素叫做base,它允许你:
为页面上的所有链接指定默认URL和默认目标:
<base target="_blank" />
通过指定_blank,可以确保iframe内的所有链接都将在外部打开。
尝试在锚标记内的target="_parent"属性。
<script type="text/javascript"> // if site open in iframe then redirect to main site
$(function(){
if(window.top.location != window.self.location)
{
top.window.location.href = window.self.location;
}
});
</script>