简体   繁体   English

获得iframe javascript的第一个父级

[英]get first parent of iframe javascript

I have a iframe inside test.aspx,when the user click on a pay button inside the Iframe,the iframe redirct to check.aspx that has same iframe 我在if.xpx里面有一个iframe,当用户点击iframe里面的付费按钮时,iframe redirct到check.aspx有同样的iframe

if payment was success on first time, then window.parent.location.href==test.aspx 如果第一次付款成功, then window.parent.location.href==test.aspx

if payment was failed the iframe redirect again to check.aspx,so now the 如果付款失败,iframe再次重定向到check.aspx,那么现在

window.parent.location.href==check.aspx

while the payement was failed the the iframe keep redirect to check.aspx and the parent location keep changing ,so for example if the client failed 3 time,inside check.aspx I need to do window.parent.parent.parent.location.href to get test.aspx redirect. 当payement失败时,iframe保持重定向到check.aspx并且父位置不断变化,所以例如如果客户端失败3次,在check.aspx里面我需要做window.parent.parent.parent.location.href获取test.aspx重定向。

when the user payment was success ,then I want to redirect the test.aspx but I can't know how much child iframe window he has! 当用户付款成功时,我想重定向test.aspx,但我不知道他有多少子iframe窗口!

I need something like 我需要类似的东西

window.parent[0].location.href=success.aspx,so I will be able to redirect the first father window. window.parent [0] .location.href = success.aspx,所以我将能够重定向第一个父窗口。

Thanks for any Help 谢谢你的帮助

Baaroz Baaroz

You can always get to the top window in JavaScript by using 您始终可以使用JavaScript进入JavaScript的顶部窗口

window.top.location.href

For more info see: Difference between window.location.href and top.location.href 有关更多信息,请参阅: window.location.href和top.location.href之间的区别

You can use: 您可以使用:

window.top.location.href

or: 要么:

var par = window.parent;
while ( par.parent ) {
    par = par.parent;
}

//par === window.top

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM