title: How to determine if content in popup window is loaded
body: <p>I need to set some contextData for a popup window from its parent.  I try this:</p>
  
  <pre><code>var some contextData = {};
  $(function() {
      $('#clickme').click(function() {
          var w = window.open('http://jsfiddle.net');
  
          w.contextData = contextData            
          //w.context data is null in the popup after the page loads - seems to get overwritten/deleted
      });
  });
  </code></pre>
  
  <p>It doesn't work, so my next thought, wait until content is loaded</p>
  
  <pre><code>var some contextData = {};
  $(function() {
      $('#clickme').click(function() {
          var w = window.open('http://jsfiddle.net');
          w.onload = function() {
              //Never Fires
              w.contextData = contextData;
  
          }
      });
  });
  </code></pre>
  
  <p>See <a href="http://jsfiddle.net/HNvn3/1/" rel="nofollow">this fiddle</a>. My onload method never fires.</p>
  
  <p>This works:</p>
  
  <pre><code>var some contextData = {};
      $(function() {
          $('#clickme').click(function() {
              var w = window.open('http://jsfiddle.net');
              setTimeout(function(){
                  if(w.someVariableSetByThePageBeingLoaded) {
                      w.contextData = contextData;
                  }
                  else{
                      setTimeout(arguments.callee, 1);
                  }
  
              }, 1);
          });
      });
  </code></pre>
  
  <p>But has obvious elegance problems (but is the current work around).</p>
  
  <p>I know you can go the other way (have the popup call back to a method on the opener/parent, but this forces me to maintain some way of looking up context (and I have to pass the key to the context to the popup in the query string).  The current method lets me capture the context in a closure, making my popup a much more reusable piece of code.</p>
  
  <p>I am not trying to do this cross domain - both the parent and popup are in the same domain, although the parent is an iframe (hard to test with jsfiddle).</p>
  
  <p>Suggestions?</p>