title: Unable to access iframe contents of same host
body: <p>I have an iframe which displays pdf file embed into it and I couldn't access the iframe element contents. </p>
  
  <pre><code>&lt;iframe id="testIFrame" src="http://localhost:8080/myproject/pdf/sample.pdf" width="800" onload="test(this)"&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>The following code in firebug console,</p>
  
  <pre><code>var iframe = document.getElementById('testIFrame');
  var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
  console.log("Iframe Document"+innerDoc);
  </code></pre>
  
  <p>gives me error,</p>
  
  <pre><code>Error: Permission denied to access property "document"
  </code></pre>
  
  <p>The same iframe can be accesible when I have an image file as URL. The cross domain error occurs only for pdf files. How can I solve this?</p>
  
  <p>EDIT:</p>
  
  <p>The URL that I'm having this iframe is <code>http://localhost:8080/myproject</code> and the iframe source point to <code>http://localhost:8080/myproject/pdf/sample.pdf</code>. And I can see in the Firebug Net panel that the pdf request is having </p>
  
  <blockquote>
    <p>Protocol - <code>http</code>, </p>
    
    <p>Domain - <code>localhost:8080</code>, and </p>
    
    <p>RemoteIP - <code>[::1]:8080</code></p>
    
    <p>And the request headers contains the refer url as <code>http://localhost:8080/denso/</code></p>
  </blockquote>
  
  <p>Am I missing something in the Same Origin Policy?</p>
  
  <p>The reason because, only FF shows a tool bar to download, print etc for pdf files embeded in iframe which can be disable by adding param <code>#toolbar=0</code> at the end of the pdf url which works in chrome. If I can access the iframe contents I can hide the toolbar with css based on this link </p>
  
  <p><a href="https://support.mozilla.org/en-US/questions/1119523" rel="nofollow">https://support.mozilla.org/en-US/questions/1119523</a></p>