从iframe动作重定向父窗口

本文讨论如何使用JavaScript从iframe中重定向其父窗口。用户点击超链接后,通过JavaScript或其他方法,可使父窗口跳转到新的URL。在Safari的最新版本中,可能需要为iframe添加HTML5的sandbox属性来允许重定向。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:Redirect parent window from an iframe action

What JavaScript do I need to use to redirect a parent window from an iframe? 我需要使用什么JavaScript从iframe重定向父窗口?

I want them to click a hyperlink which, using JavaScript or any other method, would redirect the parent window to a new URL. 我希望他们单击​​超链接,该超链接将使用JavaScript或任何其他方法将父窗口重定向到新URL。


#1楼

参考:https://stackoom.com/question/2R3d/从iframe动作重定向父窗口


#2楼

这样可以解决苦难。

<script>parent.location='http://google.com';</script>

#3楼

尝试使用

window.parent.window.location.href = 'http://google.com'

#4楼

通过同一父项中的iframe重定向父项窗口中的iframe:

window.parent.document.getElementById("content").src = "content.aspx?id=12";

#5楼

window.top.location.href = 'index.html';

This will redirect the main window to the index page. 这会将主窗口重定向到索引页面。 Thanks 谢谢


#6楼

@MIP is right, but with newer versions of Safari, you will need to add sandbox attribute(HTML5) to give redirect access to the iFrame. @MIP是正确的,但是在Safari的较新版本中,您将需要添加沙箱属性(HTML5)以提供对iFrame的重定向访问。 There are a few specific values that can be added with a space between them. 可以添加一些特定的值,并在它们之间添加一个空格。

Reference(you will need to scroll): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe 参考(您需要滚动): https : //developer.mozilla.org/zh-CN/docs/Web/HTML/Element/iframe

Ex: 例如:

<iframe sandbox="allow-top-navigation" src="http://google.com/"></iframe>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值