gpt4 book ai didi

javascript - iframe 上的链接在 IFrame 中创建页面的另一个 View

转载 作者:行者123 更新时间:2023-12-02 18:39:26 26 4
gpt4 key购买 nike

我创建了一个 html 并将其用作 iframe 的源。

在 iframe 中,我在 div 上添加了一个链接(请参阅下面的示例代码)

<div onclick="location.href='/cybersecurity/risk-management/index.cfm'; location.href='_parent';" >
<b>Sample Text</b><br />
<span>
Sample Text
</span>
</div>

当我尝试单击 iframe 页面内的 div 时。它在 iframe 内创建页面的另一个 View 。但对于 iframe 中的 anchor 来说效果很好,<a href="linkhere" target="_parent" >This is an anchor!</a> 。如何在 onClick 上添加 JavaScript我的 div?

我还尝试使用<base target="_parent" /> ,但它不起作用。

最佳答案

您想要设置最顶层窗口(父窗口)的位置,而不是设置当前窗口(iframe)的window.location.href

window.top.location.href = 'foobar'

您还可以使用 window.parent ,它将使用当前窗口的直接父窗口,但在大多数情况下,使用 window.top 更安全,因为您实际上想要位于最上面的父窗口。

关于javascript - iframe 上的链接在 IFrame 中创建页面的另一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16978213/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com