0

I am working on a website in Yii. The situation is like this. In the website, the users are provided a piece of code that is like this:

<iframe height="700" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="http://djoneclick.com/index.php?r=webservice/form&id=6b720ff1c3cdce6c278e784a3228fd9fadc6d864" title="" >
<a href="/index.php?r=webservice/form&id=6b720ff1c3cdce6c278e784a3228fd9fadc6d864" title="">

</a>
</iframe>

User can embed this anywhere they want and take inquiries from the desired audience. This iframe includes the src which is a form that submits to a controller in Yii. In the controller, upon having a specif if condition true, it redirects to the externel url. It redirects but the contents of the url (to which it is redirected) are displayed in the iframe. What I want is to actually redirect to that url. I have spent hours upon R&D for this but could not find any solution. any help?

Saani
  • 791
  • 7
  • 28
  • 68
  • Maybe this helps you out: http://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action – Benjamin Sep 30 '15 at 10:49
  • This states to use this, `window.top.location.href = "http://www.example.com";` But i dont know, where to use this in my code? – Saani Sep 30 '15 at 10:51
  • Are you making ajax call while submit a form? – sandeepsure Sep 30 '15 at 10:56
  • No, form is submitting as does the normal form. – Saani Sep 30 '15 at 11:03
  • Do you have access to the code of the iframe content? Would it be possible for you to move the condition check to the client side? If so, you could overwrite the onsubmit-event of the form, you are sending, with javascript-code that checks the given condition and then, if it is true, executes the code line stated above... – Benjamin Sep 30 '15 at 11:03
  • 1
    Submit a form using Ajax and once you get response from ajax execute `window.top.location.href = "http://www.yoursite.com";` – sandeepsure Sep 30 '15 at 11:05
  • sandeepsure's suggestion is even better since it allows you to keep the condition check in the controller – Benjamin Sep 30 '15 at 11:09
  • @sandeepsure this seems logical, But can u kindly put some code as an example? – Saani Sep 30 '15 at 11:54

2 Answers2

1
$("#idForm").submit(function() {

var url = "path/to/your/script.php"; // the script where you handle the form input.

$.ajax({
       type: "POST",
       url: url,
       data: $("#idForm").serialize(), // serializes the form's elements.
       success: function(data)
       {
           window.top.location.href = "http://www.yoursite.com";
       }
     });

      return false; // avoid to execute the actual submit of the form.
});
sandeepsure
  • 1,113
  • 1
  • 10
  • 17
0

Try this after the condition is true in your controller:

echo "<script>";
echo "this.parent.location.href = '$externel_url'";
echo "</script>";