我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。

注意:iframe和父页面是同一个域。


当前回答

使用目标属性:

<a target="_parent" href="http://url.org">link</a>

其他回答

使用JavaScript:

window.parent.location.href= "http://www.google.com";

我找到了一个简单的解决办法

<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>

尝试在锚标记内的target="_parent"属性。

是的,我找到了

<base target="_parent" />

这对于打开在iframe中打开的所有iframe链接很有用。

And

$(window).load(function(){
    $("a").click(function(){
        top.window.location.href=$(this).attr("href");
        return true;
    })
})

这可以用于整个页面,也可以用于页面的特定部分。

谢谢你们的帮助。