回答
我发现最好的解决方案是使用基地标签。将以下内容添加到iframe页面的头部:
<base target="_parent">
这将加载父窗口中页面上的所有链接。如果你希望你的链接,加载在一个新的窗口,使用:
<base target="_blank">
此标记在所有浏览器fully supported。
使用目标属性:
<a target="_parent" href="http://url.org">link</a>
尝试target="_parent"
属性的anchor tag
内。
如上所述,您可以使用目标属性,但它在技术上已在XHTML中弃用。这留下了您使用JavaScript,通常像parent.window.location
。
有一个DOM对象调用base
它允许你:“指定页面上的所有链接默认URL和默认的目标:”通过指定“_blank”
<base target="_blank" />
你要确保里面的所有链接iframe将在外部打开。
使用JavaScript:
window.parent.location.href= "http://www.google.com";
<a target="parent">
在新标签/窗口将打开链接... <a target="_parent">
将打开在父/当前窗口的链接,而无需打开新的标签页/窗口。 Don't_forget_that_underscore!
最通用的和最跨浏览器的解决方案是避免使用“基地”标签的,而是用“a”标记的目标属性:
<a target="_parent" href="http://www.stackoverflow.com">Stack Overflow</a>
的<base>
标签是功能较少,浏览器在文档中的位置要求不一致,需要更多的跨浏览器测试。根据您的项目和情况,实现<base>
标签的理想跨浏览器放置可能很困难,甚至完全不可行。
使用<a>
标记的target="_parent"
属性执行此操作不仅更适合浏览器,还允许您区分要在iframe中打开的那些链接以及要在父级打开的链接。
如果您在网页中使用iframe,则可能会在通过iframe中的HTML超链接(锚标记)更改整个页面时遇到问题。有两种解决方案可以缓解这个问题。
解决方案1.您可以使用以下示例中给出的锚标记的目标属性。
<a target="_parent" href="http://www.kriblog.com">link</a>
解决方案2.您也可以在iframe和JavaScript的父窗口中打开一个新页面。
<a href="#" onclick="window.parent.location.href='http://www.kriblog.com';">
记住⇒target="_parent"
已过时,XHTML,但它仍然是在HTML 5.x中支持
更可以从下面的链接 http://www.kriblog.com/html/link-of-iframe-open-in-the-parent-window.html
读你可以使用任何选项
只有父页面的情况下:
,如果你想打开所有链接到父页面或父级iframe中,然后在iframe的头部分中使用以下代码:
<base target="_parent" />
OR,如果你想开一家特定链接到父页面或父IFRAME
,那么您可以采取以下方式:
<a target="_parent" href="http://specific.org">specific Link</a>
<a href="http://normal.org">Normal Link</a>
OR
万一嵌套iframe的:
如果想打开所有链接到浏览器窗口(在浏览器的URL重定向),那么您可以采取以下的iframe的头部分代码:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
</script>
OR
如果要打开特定链接进入浏览器窗口(在浏览器url中重定向),则使用以下方法:
<a href="http://specific.org" target="_top" >specific Link</a>
或
<a href="javascript:top.window.location.href='your_link'">specific Link</a>
<a href="javascript:top.window.location.href='http://specific.org'">specific Link</a>
<a href="http://normal.org">Normal Link</a>
耶,我发现
<base target="_parent" />
这个有用的开放在iframe中打开的所有链接的iframe。
而且
$(window).load(function(){
$("a").click(function(){
top.window.location.href=$(this).attr("href");
return true;
})
})
这一点我们可以使用整个网页或网页的特定部分。
谢谢大家的帮助。
<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>
尝试target="_top"
<a href="http://example.com" target="_top">
This link will open in same but parent window of iframe.
</a>
- 1. 当iframe不是来自同一个域时,如何强制从iframe中打开父窗口中的链接?
- 2. iframe强制链接在当前窗口中打开
- 3. 父窗口中的iframe中的打开链接
- 4. 如何强制链接在新窗口中自动打开?
- 5. 强制iFrame链接(在嵌入的Google Doc中)在新窗口中打开
- 6. 在父窗口中打开iFrame中的链接(无法控制子网站)
- 7. 如何只打开父窗口上的iframe中的一些链接
- 8. 如何强制在新窗口打开电子邮件链接
- 9. 如何从父窗口顶部的iframe中打开colorbox
- 10. iframe中的链接更改父窗口
- 11. 是什么导致iframe在父窗口内打开新链接?
- 12. 如何通过iframe中的链接打开新窗口
- 13. 如何在弹出的iframe窗口中打开链接
- 14. 打开从iFrame到父窗口的模态窗口
- 15. 强制HTML链接在新窗口中打开
- 16. 强制链接在新窗口中打开
- 17. 从iframe打开模式窗口进入父窗口
- 18. 从iframe打开窗口
- 19. 在iFrame中的新窗口中打开链接
- 20. 在新窗口中的iframe中打开链接
- 21. 强制数据链接打开一个新窗口
- 22. HTML:如何强制链接在新标签中打开,而不是新窗口
- 23. 如何在主窗口中打开iframe中的链接而不是iframe中的链接?
- 24. 在新窗口中打开iframe(fancybox)的链接
- 25. 强迫在同一域的同一窗口中打开链接
- 26. 在包含启动链接的iframe的窗口中打开链接
- 27. 在Fancybox的父窗口中打开内部链接
- 28. 在一个iframe中打开新窗口链接
- 29. 如何在iFrame加载到父窗口的按钮链接?
- 30. 从iframe中的变量打开链接
我试试这个,是我在新窗口中 – 2009-06-24 11:52:17
+1开放,基本目标=“_父”的作品,但目标=“_父”,决不放过我! – 2012-03-14 05:18:56
它适用于SVG! – Rustam 2012-06-22 11:28:31