title: Is there a way to fix nested document.write in window.open?
body: <p>I have a button that will open a new blank window using <code>window.open</code>, but will write a multiplication table on it.</p>
  <p>Here's my code.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>document.getElementById("p").innerHTML = "&lt;button id = 'mult' type = 'button'&gt;Multiplication Tables&lt;/button&gt;";
  document.getElementById("mult").onclick = function() {
    newWindow()
  };
  document.getElementById("close").onclick = function() {
    close()
  };
  
  function newWindow() {
    var multiplyWindow = window.open("", "multiplicationTables", "width = 300, height = 200");
    multiplyWindow.document.write(multiply());
  }
  
  function multiply() {
    document.write("&lt;center&gt;&lt;table border='1px'&gt;");
    for (var a = 5; a &lt; 11; a++) {
      document.write("&lt;tr style='height:40px'&gt;");
      for (var b = 5; b &lt; 11; b++) {
        document.write("&lt;td style='width:40px'&gt;&lt;center&gt;&lt;font size='4'&gt;" + a * b + "&lt;/center&gt;&lt;/font&gt;&lt;/td&gt;");
      }
      document.write("&lt;/tr&gt;");
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p id="p"&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>I know the problem is because when I run the <code>multiply()</code> function, we are nesting a <code>document.write</code>. I thought of using <code>document.getElementById</code>, but the problem with that is (I think) there is no ID of a new window opened using <code>window.open</code>.</p>
  <p>Instead, what happens is the multiplication table is printed on the original window, and in the new pop-up window, an &quot;undefined&quot; message shows up. This makes sense, again because of the nested <code>document.write</code>s.</p>
  <hr />
  <p>Two questions:</p>
  <ol>
  <li>How do I fix this nested <code>document.write</code> and still get it to work?</li>
  <li>Is there a way to assign an ID to a new window using <code>window.open</code>?</li>
  </ol>
  <hr />
  <p>Additionally, I look at this SO post: <a href="https://stackoverflow.com/questions/7450762/document-write-nested-in-document-write">document.write nested in document.write</a>, but the only answer was simply not to use <code>document.write</code>.</p>
  <p>Thank you in advance.</p>