title: Execute JavaScript in window.open() generated window
body: <p>My problems seem to be the following:</p>
  
  <p>I have this code:</p>
  
  <pre><code>function openNew(theImage){
  
      var theHTML = "&lt;!doctype html&gt;&lt;html&gt;&lt;head&gt;&lt;script src='../js/windowScript.js'&gt;&lt;/script&gt;&lt;title&gt;EditWindow&lt;/title&gt;&lt;/head&gt;&lt;body&gt;&lt;div id='canvasContainer'&gt;&lt;/div&gt;&lt;img id='removeable' src='"+theImage+"'&gt;&lt;button id='cropMe'&gt;Crop it!&lt;/button&gt;&lt;/body&gt;&lt;/html&gt;";
      var editWindow = window.open("","","width=1000 height=800 titlebar=0");
  
  
      editWindow.document.write(theHTML);
  }
  </code></pre>
  
  <p>which opens a new window with the "theHTML"-Strings content.
  And as you can see, it also adds the script "windowScript.js" to the new window.</p>
  
  <p><strong>windowScript.js:</strong></p>
  
  <pre><code>window.onload = function(){
  
      document.getElementById("cropMe").addEventListener("click",removeImg);
  
      alert("it began");
  
  }
  
  function removeImg(){
  
      var imgTAG = document.getElementById("removeable");
      var imgURL = imgTAG.getAttribute("src");
      if(imgTAG.parentNode)
          imgTAG.parentNode.removeChild;
  
  }
  </code></pre>
  
  <p>but this script is never executed.
  If I check the script via the inspector of chrome, it tells me it's there and it even detects if there are errors in it, but it does not get executed whatsoever.</p>
  
  <p>Is there a workaround to get the script running in the new window, without injecting it via <code>editWindow.document.write();</code>
  ?</p>
  
  <p>Thank you in advance for your support!</p>