I have a web page with an embedded iframe (iframe contents hosted under the same domain). Inside that iframe there is a link that is supposed to open a PDF file in a new tab when clicked.
iframe inclusion HTML:
<iframe src="./pages/ins_and_outs/ins_and_outs.html" width="100%" height="800" frameborder="0" id="ins-and-outs" target="ins-and-outs" sandbox="allow-scripts allow-top-navigation allow-popups"></iframe>
iframe:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
...
<a href="./ins-and-outs/downloads/ins-and-outs.pdf" target="_blank">Open our infographic</a>
...
</html>
Upon clicking the link to the PDF in Google Chrome, it opens a new tab showing a blank page but with the PDF's URL in the address bar.
I first thought it was an issue with the PDF itself, so I manually copy pasted its URL in the browser's address bar but found it displayed without issues.
I then went on and tested my page in Firefox, clicking the link there resulted in the PDF displaying correctly in a new tab.
I've also tried placing the link outside the iframe for test purposes, which works as well.
My conclusion is that it's a specific issue with having a PDF open in a new tab by clicking a link in an iframe, and only in Google Chrome.
Any ideas to what exactly is causing this, and what kind of solution would be possible?
What I'm doing as a quickfix now is adding the "download" attribute to the link, so it no longer displays the PDF but just downloads it.
<a href="./ins-and-outs/downloads/ins-and-outs.pdf" target="_blank" download>Open our infographic</a>
All you need to do is add #view=fitH to the end of the source attribute. That's it! fitH stands for fit horizontal, and this will make the PDF in our iframe fit the width of the screen.
I found something! I know your question was 2 years ago, but if you use the sandbox "allow-popups-to-escape-sandbox" in your iframe, this will work.
Here is an example:
<iframe id="blue" src="iframe.html" sandbox="allow-popups-to-escape-sandbox"></iframe>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With