title: How to add a button inside a new window object and call the function in JavaScript?
body: <p>I'm new to JavaScript and trying to learn. I have a button which opens up a new window which then pops up an alert message after 10 seconds using the setTimeout method. But I would like to have a button that stops it before the message appears using the clearTimeout method. I managed to create a button but when I click the button nothing happens so i don't know why this doesn't work and would appreciate any help. Here is my code:</p>
  
  <pre><code>function newWindow4(){
      var window4 = window.open('', '_blank', 'location=no');
      window4.document.write('In 10 seconds there will be a message!');
      var x = setTimeout(function(){
          window4.alert('Here is the message');
      }, 10000);
  
      window4.document.write('&lt;button onclick="stop()"&gt;Stop&lt;/button&gt;');
  
      function stop(){
          clearTimeout(x);
      }   
  }
  </code></pre>