10

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.

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.

Pseudocode:

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

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

4

1 回答 1

12

你可以试试

$("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)

这不是充分的证据。即如果另一个站点添加一个阶段等可能会中断,但如果您对另一个站点没有任何控制权,它是我能想到的最好的。

于 2012-04-24T15:56:08.193 回答