title: Error: Uncaught TypeError: Cannot read property 'window' of null at HTMLDivElement.closeIframeContainer
body: <p>I have a simple block which contains an iframe, I would like a user to be able to close the iframe using a button. But unfortunately I am getting the following error.</p>
  
  <p>Here is what I have so far</p>
  
  <p>JS </p>
  
  <pre><code>  document.querySelector(.video-close_btn).addEventListener('click', closeIframeContainer);
      var closeIframeContainer =function(){
          window.parent.postMessage("event=closeiframe", "*");
      };
  
      window.addEventListener("message", receiveMessageFromIframe, false);
      function receiveMessageFromIframe(msg) {
          if (event == "closeiframe") {
              document.getElementById('iframe-container').remove();
          }else{
             alert('hehehe');
          }
      }
  </code></pre>
  
  <p>Here is index.html with iframe</p>
  
  <pre><code>&lt;div id="iframe-container"&gt;
  
              &lt;iframe src="/videoexplainer/data.html" style="border:none"&gt;&lt;/iframe&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is data.html</p>
  
  <pre><code> &lt;div id="video-close_btn" class="video-btn"&gt;
                      &lt;img src="images/x.png" /&gt;
                  &lt;/div&gt;
  </code></pre>
  
  <p>unfortunately its not working, what do I need to do get what I want? any help or suggestions will be appreciated thanks.</p>