Redirect Detection in iFrame

Perhaps I am asking the wrong question, so I will provide a small amount of detail about what I'm trying to accomplish.

I am using a third-party web application to track support tickets. They provide code for the 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 the same, hard-coded redirection value. This causes one of my sites to switch domains after sending.

I thought I could embed my form in an iFrame, detect redirection when the form was submitted successfully, and instead redirect to one of my own pages.

pseudo code:

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

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

+7
source share
1 answer

You can try

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

to detect downloads and frame updates

and if the redirection occurs on the second boot

 //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++; }); 

If the number of steps is greater, just change x to the number of steps

 if(timesRefreshed == x) 

This is not complete evidence. those. if it can break, if another site adds a scene, etc., but this is the best I can come up with if you do not have control over another site.

+9
source

All Articles