我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
我需要在相同的父页面中打开链接,而不是在一个新页面中打开它。
注意:iframe和父页面是同一个域。
当前回答
是的,我找到了
<base target="_parent" />
这对于打开在iframe中打开的所有iframe链接很有用。
And
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
这可以用于整个页面,也可以用于页面的特定部分。
谢谢你们的帮助。
其他回答
使用JavaScript:
window.parent.location.href= "http://www.google.com";
尝试在锚标记内的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>
使用目标属性:
<a target="_parent" href="http://url.org">link</a>
如果你在你的网页中使用iframe,你可能会遇到一个问题,而改变整个页面通过HTML超链接(锚标签)从iframe。有两种解决方案可以缓解这个问题。
解决方案1。您可以使用锚标记的目标属性,如下例所示。
<a target="_parent" href="http://www.kriblog.com">link</a>
解决方案2。您还可以使用JavaScript从iframe在父窗口中打开一个新页面。
<a href="#" onclick="window.parent.location.href='http://www.kriblog.com';">
记住,在XHTML中,target="_parent"已弃用,但在HTML 5.x中仍然支持。
更多信息可从以下链接阅读 http://www.kriblog.com/html/link-of-iframe-open-in-the-parent-window.html