我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
当前回答
是的,我找到了
<base target="_parent" />
这对于打开在iframe中打开的所有iframe链接很有用。
And
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
这可以用于整个页面,也可以用于页面的特定部分。
谢谢你们的帮助。
其他回答
我找到了一个简单的解决办法
<iframe class="embedded-content" sandbox="allow-top-navigation"></iframe>
allow-top-navigation 允许iframe更改parent.location。 更多信息https://javascript.info/cross-window-communication
<a target="parent">将在新选项卡/窗口中打开链接…<a target="_parent">将在父/当前窗口中打开链接,而不会打开新的选项卡/窗口。唐't_forget_that_underscore !
如前所述,您可以使用目标属性,但从技术上讲,它在XHTML中已被弃用。这就需要使用javascript,通常是parent.window.location。
有一个HTML元素叫做base,它允许你:
为页面上的所有链接指定默认URL和默认目标:
<base target="_blank" />
通过指定_blank,可以确保iframe内的所有链接都将在外部打开。
试目标= " _top "
<a href="http://example.com" target="_top">
This link will open in same but parent window of iframe.
</a>