title: delay in window.addEventListener
body: <p>I want to call onMessageReceived after some delay.</p>
  
  <pre><code>window.addEventListener("message", onMessageReceived);
  
  function onMessageReceived(event)
  {
      var messageData = JSON.parse(event.data);
  
      if (messageData.type === "panelExpanded")
      {
          expandButton.style.display = 'none';
      }
  }
  </code></pre>
  
  <p>I want to hide the expandButton when data received is "panelExpanded"</p>
  
  <p>I want a delay in the onMessageRecieved method. I tried setInterval and setTimeout but none of this work.</p>
  
  <pre><code>setTimeout(window.addEventListener("message", onMessageReceived), 3000);
  window.addEventListener ('message', function () {
      setTimeout (onMessageReceived, 3000);
  }, false);
  
  setInterval(window.addEventListener("message", onMessageReceived), 3000);
  window.addEventListener ('message', function () {
      setInterval (onMessageReceived, 3000);
  }, false);
  </code></pre>
  
  <p>How can i add a delay? Help would be appreciated. Thanks in advance</p>