0

Let's suppose I open a web-page and run this Javascript:

var test = "Success";
window.open(window.location.href);

Then, in the opened window

console.log(window.parent.test);

will yield undefined. I can solve the problem by doing this:

var test = "Success";
window.open(window.location.href).myParent = window;

and then, in the other window

console.log(test);

will yield "Success". So, the problem can be solved, but I wonder why is the opened window unable to reach the parent window's variables out of the box?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175

1 Answers1

1

Have you tried window.opener.test ?

or specifically: console.log(window.opener.test);

This link explains the difference between window.parent and window.opener:When to use window.opener / window.parent / window.top

Community
  • 1
  • 1
nejinx
  • 349
  • 2
  • 6