I have an iframe which displays pdf file embed into it and I couldn't access the iframe element contents.
<iframe id="testIFrame" src="http://localhost:8080/myproject/pdf/sample.pdf" width="800" onload="test(this)"></iframe>
The following code in firebug console,
var iframe = document.getElementById('testIFrame');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
console.log("Iframe Document"+innerDoc);
gives me error,
Error: Permission denied to access property "document"
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?
EDIT:
The URL that I'm having this iframe is http://localhost:8080/myproject
and the iframe source point to http://localhost:8080/myproject/pdf/sample.pdf
. And I can see in the Firebug Net panel that the pdf request is having
Protocol -
http
,Domain -
localhost:8080
, andRemoteIP -
[::1]:8080
And the request headers contains the refer url as
http://localhost:8080/denso/
Am I missing something in the Same Origin Policy?
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 #toolbar=0
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