Javascript open new tab, and wait for it to close

后端 未结 3 1478
故里飘歌
故里飘歌 2021-02-19 19:02

I want to open a new tab for a bank payment on my website using javascript, and without the main window navigating away,

when the user is back from the bank payment to a

3条回答
  •  伪装坚强ぢ
    2021-02-19 19:25

    The best approach with data transfer from the child window I found.

    Parent code

    window.open(url);
    await new Promise(resolve => window.addEventListener('custom', resolve));
    

    Child code

    if(window.opener) {
      const customEvent = new CustomEvent('custom', { detail: {} });
      window.opener.dispatchEvent(customEvent);
      window.close();
    }
    

提交回复
热议问题