-3

Suppose My Website is https://example.com I have loaded iframe inside that having src https://example2.com/iframe

When my Iframe is loaded, then inside that iframe i have a button which redirect to https://example3.com. so example3 doesn't allow to open inside Iframe, so my code is failing.

For workaround of this, I decided that I will open https://example3.com in another window and will do some stuff, close that window. Next, I will return to https://example.com (Website in which iframe has loaded) and wanted to add one params to my iframe's src, so that i can identify that i have completed my task of https://example3.com and want to change and reload the src of Iframe.

Please help me how can i solve this. Please suggest some other better way as well if possible.

Please feel free to add the comment in case i can help you to understand my problem better.

Vikash
  • 3,391
  • 2
  • 23
  • 39
  • Now what is the actual problem? Getting a reference to the iframe? Changing the src of the iframe? Someting else? – Teemu Dec 13 '18 at 18:33
  • I suggest you read [ask] and [mcve] one more time, and then edit the question accordingly, as in its present state it most likely will be closed being off topic. – Asons Dec 13 '18 at 18:34
  • 1
    There will be no way to know if you actually did anything on the site you don't control before you closed it's window – charlietfl Dec 13 '18 at 18:35
  • I will not close that example3.com window. but i can sed the postMessage from example3.com's window and i can receive at example.com window, then i will change current iframe url ? @charlietfl – Vikash Dec 13 '18 at 18:46
  • But you don't control code on example3 do you? If you do why couldn't you set it up to load in iframe? – charlietfl Dec 13 '18 at 18:50

1 Answers1

1

Since it sounds like you don't control the code on the site in new window about the only practical thing you can do would be to set an interval to check if the new window you opened with window.open() is closed from the page you opened it.

Then once you determine it is closed add a prompt of some sort for the user

var otherWindow = window.open('example3.com');

var timer = setInterval(function(){
   if(otherWindow.closed){
      clearInterval(timer);
      if(confirm('Did you complete that step?')){
        // adjust iframe url
      }
   }
},1000);// check every second if it is closed
charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • So, in my case at otherWindow after doing some task successfully. it will redirect to my iframe src with some flag https://example2.com/iframe?isSuccess=true, so i can check every second that otherWindow.location.href=https://example2.com/iframe?isSuccess=true, then send postMessage to parent window and close that otherWindow. and when my parentWindow receives that postMessage, then change the Iframe src. is it correct ? – Vikash Dec 13 '18 at 19:04
  • I'm not 100% sure you can get the otherWindow href or not. Idea sounds about right though. Might also be able to use Storage events in example2 page. Your workflow is still a little bit confusing to me – charlietfl Dec 13 '18 at 19:14