title: Issues with window.print() onLoad
body: <p>I'm trying to open the print dialog when a page is done loading. Using the code below, I get no errors and the window opens, but the onload never seems to fire and the print dialog does not open (Firefox and Chrome -- haven't tested other browsers).</p>
  
  <p>I've tried these :</p>
  
  <pre><code>var printWindow = window.open(result.url);
  
  printWindow.window.onload = function () {
      printWindow.window.print();
      console.log("Printing page");
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>var printWindow = window.open(result.url);
  
  printWindow.onload = function () {
      printWindow.print();
      console.log("Printing page");
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>var printWindow = window.open(result.url);
  printWindow.addEventListener("load", function() {
      printWindow.print();
      console.log("Got here");
  });
  </code></pre>
  
  <p>An example of what the result.url looks like:</p>
  
  <p><a href="http://ourserver/arcgis/rest/directories/arcgisoutput/OurTools/Print_Tool_Adv_GPServer/_ags_WebMap_de458080-c19a-11e6-8ade-005056a65a05.PDF" rel="nofollow noreferrer">http://ourserver/arcgis/rest/directories/arcgisoutput/OurTools/Print_Tool_Adv_GPServer/_ags_WebMap_de458080-c19a-11e6-8ade-005056a65a05.PDF</a></p>
  
  <p>I'm trying to see if this <a href="https://stackoverflow.com/questions/3030859/detecting-the-onload-event-of-a-window-opened-with-window-open">post</a> applies to my case, and how I can use the answer to my advantge. My original window that allows the user to generate the new url is at <a href="http://ourserver/ourapp" rel="nofollow noreferrer">http://ourserver/ourapp</a> whereas the new url is at <a href="http://ourerver/arcgis/" rel="nofollow noreferrer">http://ourerver/arcgis/</a>...
  I don't believe this is the same situation, but I am trying to see how it is possible to exploit the answer of the suggested duplicate if this is the case.</p>
  
  <p><strong>UPDATE</strong>
  So I finally got the signal to fire using a postMessage approach. However, I think i'm running into a window.print() specific problem, because the print statement comes up to the console, but I still have the following issues:</p>
  
  <ul>
  <li>On chrome, no print dialog opens</li>
  <li><p>On Firefox, print dialog opens, but it prints about:blank, and not the url I'd opened the window with...seems like the page hadn't loaded completely before the dialog opened or something (same thing that happens when I call printWindow.print() directly without a handler).</p>
  
  <pre><code>  var printWindow = window.open(result.url);
  
    var eventMethod = window.addEventListener ? "addEventListener" : "attachEvent";
    var eventer = window[eventMethod];
    var messageEvent = eventMethod == "attachEvent" ? "onmessage" : "message";
  
    // Listen to message from child window
    eventer(messageEvent,function(e) {
      console.log('origin: ', e.origin)
  
    // Check if origin is proper
    if( e.origin != 'http://ourserver' ){ return }
      console.log('parent received message!: ', e.data);
  
      try {
        //attempt to deserialize function and execute as closure
        eval('(' + decodeURI(e.data) + ')();');
      } catch(e) {}
    }, false);
  
    printWindow.opener.postMessage({serializeFunction(openPrintDialog)}, 'http://ourserver');
  </code></pre></li>
  </ul>
  
  <p>The code references these functions:</p>
  
  <pre><code>  function serializeFunction(f) {
      return encodeURI(f.toString());
    }
  
    function openPrintDialog() {
      printWindow.print();
      console.log("Got here");
    }
  </code></pre>