0

I have iframe on my site. In this iframe another site is displaying. After submitting form in iframe location.href is changed. It leads to top level window redirect.

So, I want to change location of iframe instead of changing location of top-level window.

How can I do that?

Thanks!

Vlad Shut
  • 33
  • 3
  • Assuming your `iframe` has an `id` of "test", you should just be able to do `document.getElementById('test').src = 'newpage.html';`. Is that not working? – Nick Oct 25 '17 at 12:21
  • @snapjs Its not exactly what I need. I need to catch redirect from iframe, prevent it, get new location from redirect, and then change iframe src property as You wrote. – Vlad Shut Oct 25 '17 at 12:24
  • This might help: https://stackoverflow.com/questions/369498/how-to-prevent-iframe-from-redirecting-top-level-window – Nick Oct 25 '17 at 12:26
  • @snapjs Thanks, but it doesn't help. Ive already try using sandbox, but it just prevent top-level window from redirecting and iframe doesn't redirect. I need iframe to redirect instead of top-level window. – Vlad Shut Oct 25 '17 at 12:31
  • Maybe I'm not understanding the problem fully, but seems like you could use [onbeforeunload](https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload) to stop the top-level window from redirecting and then instead redirect the iframe. – Nick Oct 25 '17 at 12:34
  • @snapjs Yes, it can be done in this way. Unfortunately, I can not find the way how to fetch new url (url for redirecting) from onbeforeunload event. – Vlad Shut Oct 25 '17 at 12:37

0 Answers0