2009-06-24 123 views

回答

517

我发现最好的解决方案是使用基地标签。将以下内容添加到iframe页面的头部:

<base target="_parent"> 

这将加载父窗口中页面上的所有链接。如果你希望你的链接,加载在一个新的窗口,使用:

<base target="_blank"> 

此标记在所有浏览器fully supported

123

使用目标属性:

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

我试试这个,是我在新窗口中 – 2009-06-24 11:52:17

+2

+1开放,基本目标=“_父”的作品,但目标=“_父”,决不放过我! – 2012-03-14 05:18:56

+0

它适用于SVG! – Rustam 2012-06-22 11:28:31

6

尝试target="_parent"属性anchor tag内。

9

如上所述,您可以使用目标属性,但它在技术上已在XHTML中弃用。这留下了您使用JavaScript,通常像parent.window.location

7

有一个DOM对象调用base它允许你:“指定页面上的所有链接默认URL和默认的目标:”通过指定“_blank”

<base target="_blank" /> 

你要确保里面的所有链接iframe将在外部打开。

30

使用JavaScript:

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

<a target="parent">在新标签/窗口将打开链接... <a target="_parent">将打开在父/当前窗口的链接,而无需打开新的标签页/窗口。 Don't_forget_that_underscore!

4

最通用的和最跨浏览器的解决方案是避免使用“基地”标签的,而是用“a”标记的目标属性:

<a target="_parent" href="http://www.stackoverflow.com">Stack Overflow</a> 

<base>标签是功能较少,浏览器在文档中的位置要求不一致,需要更多的跨浏览器测试。根据您的项目和情况,实现<base>标签的理想跨浏览器放置可能很困难,甚至完全不可行。

使用<a>标记的target="_parent"属性执行此操作不仅更适合浏览器,还允许您区分要在iframe中打开的那些链接以及要在父级打开的链接。

1

如果您在网页中使用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

16

读你可以使用任何选项

只有父页面的情况下:

,如果你想打开所有链接到父页面或父级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> 
0

耶,我发现

<base target="_parent" /> 

这个有用的开放在iframe中打开的所有链接的iframe。

而且

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

这一点我们可以使用整个网页或网页的特定部分。

谢谢大家的帮助。

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

尝试target="_top"

<a href="http://example.com" target="_top"> 
    This link will open in same but parent window of iframe. 
</a> 
相关问题