最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detect redirect in iFrame - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question asked Apr 24, 2012 at 15:34 mrtshermanmrtsherman 39.9k23 gold badges89 silver badges111 bronze badges 2
  • maybe you can bind the form submit event using jquery, handle the form submission yourself and check the response code? – Reto Aebersold Commented Apr 24, 2012 at 15:40
  • @RetoAebersold - great idea, I actually thought of this myself. But the form submits attachments so I can't send it via AJAX instead. – mrtsherman Commented Apr 24, 2012 at 15:41
Add a comment  | 

1 Answer 1

Reset to default 15

You could try

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

to detect the frame loading and refreshing

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++; 

});

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.

发布评论

评论列表(0)

  1. 暂无评论