2

I'm using window.open(...) to open a completely new window (same domain, same subdomain, same directory, same everything, but a different .html file). In the child window, I'm using this to send messages back to the parent:

window.opener.postMessage({status:'ready'}, window.opener.location);

It works great in Chrome and Firefox ... but not in Safari. Here are some alternatives I tried that did not work:

window.opener.* // no matter what I put, Safari says .opener is an empty object
window.parent // child refers to self despite different window, same subdomain

How can I get a reference to the parent window so I can send postMessage(...) messages back?

Steverino
  • 2,099
  • 6
  • 26
  • 50
  • Have you tried `this.opener`? Is there a variable reference to the opened `window` at `opener`? Can you include full `html`, `javascript` tried at Question? – guest271314 Nov 06 '16 at 01:07
  • Can't provide full files, this comes from production code I shouldn't share. Does Safari require you to explicitly create a `window` variable? Not used to this, it's not required in the other browsers I've been working in. If you take my word for it, there's no explicit (or implicit that I can tell) reassignment of the `window` variable. But logging `console.log(window.opener)` for example, yields an object of type `Window` with "no properties". – Steverino Nov 06 '16 at 01:37
  • Have not tried safari. Not sure. By variable mean `var w = window.open("/path/to/resource/")`. `w` references opened `window` at parent `window`. – guest271314 Nov 06 '16 at 01:40
  • _"Can't provide full files, this comes from production code I shouldn't share."_ See [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Without ability to reproduce issue, how can Question be answered accurately? – guest271314 Nov 06 '16 at 01:47
  • A possible alternative approach could be to utilize `SharedWorker` , see [How can I load a shared web worker with a user-script?](http://stackoverflow.com/questions/38810002/how-can-i-load-a-shared-web-worker-with-a-user-script/) – guest271314 Nov 06 '16 at 01:56

0 Answers0