title: Close an injected iframe
body: <p>I have a content script that runs from my chrome extension.
  this script injects an <code>iframe</code> to the body of the current page.
  i want to have the possibility to close the <code>iframe</code> from within the <code>iframe</code>.
  how do i do this?
  when i searched this issue on the web, almost each solution uses the <code>window.parent.document</code> property which for some reason is undefined in my case. any ideas?</p>
  
  <p><strong>EDIT - Code Sample:</strong></p>
  
  <p>in the HTML of the <code>iframe</code>:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function frameClose() {
              var windowFrames = window.parent.frames;
              for (var i = 0; i &lt; windowFrames.length; i++) {
                  var aFrame = windowFrames[i];
                  if (aFrame.name == 'myFrame') {
                      alert('in frame');
                      // WHAT TO DO HERE?
                      // window.parent.document is undefined
                      // aFrame.parentNode.removeChild(aFrame); - THIS DOES NOT WORK ALSO
                      break;
                  }
              }
          }
      &lt;/script&gt;
  </code></pre>
  
  <p>this is how i inject the <code>iframe</code>:</p>
  
  <p><em>Extension.js</em></p>
  
  <pre><code>chrome.browserAction.onClicked.addListener(function(tab) {
  
      chrome.tabs.executeScript(null, {
          file : "/js/PushIFrame.js"
      }, function() {
          if (chrome.extension.lastError) {
          }
      });
  });
  </code></pre>
  
  <p>and in <em>PushIFrame.js</em> i have: </p>
  
  <pre><code>chrome.extension.sendMessage({
      action: "pushFrame",
      source: pushIframe(document)
  });
  
  function pushIframe(document) {
      var existingFrame = document.getElementById('bmarkFrame');
      if (existingFrame == null) {
          var temp = document.createElement('iframe');
          temp.id = 'myFrame';
          temp.name = 'myFrame';
          temp.setAttribute('scrolling', 'no');
          temp.setAttribute('allowtransparency', 'true');
          temp.style.border = 'none';
          temp.style.height = '100%';
          temp.style.width = '100%';
          temp.style.position = 'fixed';
          temp.style.zIndex = 99999999;
          temp.style.top = 0;
          temp.style.left = 0;
          temp.style.display = 'block';
          temp.src = 'https://www.mysite.com/';
  
          document.body.appendChild(temp);
      }
      else {
          existingFrame.style.display = 'block';
      }
  }
  </code></pre>