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

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


当前回答

使用目标属性:

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

其他回答

你可以使用任何选项

如果只有父页面:

如果你想打开父页面或父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>

or

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

使用目标属性:

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

使用JavaScript:

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

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

如前所述,您可以使用目标属性,但从技术上讲,它在XHTML中已被弃用。这就需要使用javascript,通常是parent.window.location。