本文介绍了检测iFrame中的重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I may be asking the wrong question here so I will provide a small amount of detail about what I am trying to accomplish.

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

I use a third party web app to track support tickets. They provide the code for a form that my users fill out and it submits to their domain. I want to use this form on two different domains, but unfortunately the third party uses a single, hard coded redirect value. This causes one of my sites to switch domains after submission.

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

I was thinking I could embed their form in an iFrame, detect the redirection on successful form submission and instead redirect to one of my own pages.

伪代码:

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

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

So back to my original question - how can I detect the redirection in the iframe?

推荐答案

你可以尝试

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

检测帧加载和刷新

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

and if the redirect happens on the second load

//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 there are more stages just change the x to the amount of stages

if(timesRefreshed == x)

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

this isnt full proof. ie if could break if the other site adds a stage etc but its the best i can think of if you dont have any control over the other site.

这篇关于检测iFrame中的重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:52