title: Function attached to window.addEventListener gets called automatically on page load
body: <p>displayMessage1() function gets called automatically on page load with values <code>{"message":null,"messageType":"ready_anchor"}</code>  </p>
  
  <p>Instead of it getting called only when the event gets fired. How do I invoke this function only when the event is fired.  </p>
  
  <pre><code>&lt;head&gt;
      &lt;script&gt;
                  function displayMessage1(event) {
                      $('#messageText').val(event.data);
                  }
  
                  if (window.addEventListener) {
                      window.addEventListener("message",displayMessage1, false);
                  } else {
                      window.attachEvent("onmessage", displayMessage1);
                  }
          &lt;/script&gt;
      &lt;/head&gt;
  </code></pre>