title: Callback for a popup window in JavaScript
body: <p>I hope I did my homework well, searching the Internets for the last couple of hours and trying everything before posting here, but I'm really close to call it impossible, so this is my last resort.</p>
  
  <p>I want a simple thing (but seems like hard in JavaScript):</p>
  
  <ol>
  <li>Click button -> Open Window (using window.open) </li>
  <li>Perform an action in the popup window and return the value to parent (opener)</li>
  </ol>
  
  <p>But I want to achieve it in a systematic way, having a callback defined for this popup; something like:</p>
  
  <pre><code>var wnd = window.open(...)
  wnd.callback = function(value) {
      console.log(value);
  };
  </code></pre>
  
  <p>I've tried defining the callback property in popup window JS code:</p>
  
  <pre><code>var callback = null;
  </code></pre>
  
  <p>Unfortunately, that does not work, as...</p>
  
  <pre><code>$('#action').click(function() {
      console.log(callback);
  });
  </code></pre>
  
  <p>... returns just that "null" I set initially.</p>
  
  <p>I've also tried setting the callback in a parent window after window load (both thru window.onload=... and $(window).ready()), none worked.</p>
  
  <p>I've also tried defining some method in child window source code to register callback internally:</p>
  
  <pre><code>function registerCallback(_callback)
  {
      callback = _callback; // also window.callback = _callback;
  }
  </code></pre>
  
  <p>But with the same result.</p>
  
  <p>And I don't have any more ideas. Sure, it would be simple setting the value using window.opener, but I'll loose much of a flexibility I need for this child window (actually an asset selector for DAM system).</p>
  
  <p>If you have some ideas, please share them.
  Thank you a million!</p>