1

I have a window that I am creating via window.open. This window displays a form. When the form is submitted, the user is taken to a new page: success.html. How can I trigger an event after success.html loads? I've tried to following:

var myWindow = window.open("http://theform.com", "THE_NAME", 
    "menubar=no,location=no,resizable=no,scrollbars=no,status=no,width=500,height=463");
myWindow.addEventListener("load", (event) => {
    console.log("Window event" + myWindow.location.href);
}, false);

No events are triggered.

Max
  • 13,084
  • 12
  • 69
  • 109

2 Answers2

1

What you can do is postMessage between windows if they have the same origin.

Learn more: SecurityError: Blocked a frame with origin from accessing a cross-origin frame (follow link even if its about iframes/frames)

Community
  • 1
  • 1
aifrim
  • 527
  • 9
  • 17
  • `postMessage` works regardless of origin. The windows should have the same domain by setting the `document.domain` property. – Max May 08 '16 at 18:48
  • I know it works regardless of origin. But it wont work if there is no code to listen and respond. What I meant by origin was: you being the one writing them. (their origin) – aifrim May 08 '16 at 20:43
0

Try putting your event listener in the success.html instead of where you are doing it right now.

Cheezy Code
  • 1,565
  • 1
  • 11
  • 17