检测iFrame中的重定向

我可能会在这里提出错误的问题,所以我会提供一些关于我想要完成的事情的细节。

我使用第三方Web应用程序来跟踪支持服务单。 它们为我的用户填写的表单提供代码,并提交到他们的域。 我想在两个不同的域上使用此表单,但不幸的是第三方使用单个硬编码重定向值。 这会导致我的一个站点在提交后切换域。

我想我可以将他们的表单嵌入到iFrame中,检测成功表单提交时的重定向,然后重定向到我自己的一个页面。

伪代码:

iframe.detectRedirection if (redirect == 'xyz.html') { //do my own redirection in main window. } 

回到我原来的问题 – 如何检测iframe中的重定向?

你可以试试

 $("iframe").load(function(){ //The iframe has loaded or reloaded. }); 

检测帧加载和刷新

如果重定向发生在第二次加载

 //var to count times iframe has loaded var timesRefreshed = 0; //detect iframe loading/refreshing $("iframe").load(function(){ //if second refresh, change frame src - ie dont count first load if(timesRefreshed == 1){ $(this).attr("src","my site url here"); } //add to times resreshed counter timesRefreshed++; }); 

如果有更多阶段,只需将x更改为阶段数量

 if(timesRefreshed == x) 

这不是完整的证据。 即如果其他网站添加了一个阶段等可能会破坏,但如果你对其他网站没有任何控制权,我可以想到它是最好的。