Reputation: 41
I have a large number of Jupyter Notebooks and in many of them I have hyperlinks to locally stored pdf documents. A short while ago the links stopped working on my iMac in Chrome. When clicking on a link, a new tab is opened with the proper address, but the page is just black. When I do this on my MacBook with exactly the same Jupyter Notebook, it works ok. I have basically the same environment on my MacBook as on my iMac. Everything is up to date. I am using Anaconda for Python and Jupyter.
When looking at the console in Chrome when this issue happens on my iMac I get the following error message: Failed to load 'http://localhost:8888/files/Cookbooks/Git%20%26%20GitHub/books/Pro_Git.pdf' as a plugin, because the frame into which the plugin is loading is sandboxed.
When I open Jupyter notebook on either Safari or Firefox, the hyperlinks are working fine. Chrome is my default browser and I would like to have this fixed. I am not very technical and I have not been able to find any solutions on the internet. Help would be very much appreciated.
Upvotes: 4
Views: 2300
Reputation: 3209
An easy fix is to use an <embed>
element instead of an <iframe>
.
You can define a helper function in your notebook:
from IPython.core.display import HTML
def pdf(url):
return HTML('<embed src="%s" type="application/pdf" width="100%%" height="600px" />' % url)
To display your PDF, use the following:
pdf('./data-ref/pluto_datadictionary.pdf')
Note: the pdf file should be stored next to your jupyter notebook
The original iframe issue is related to the Content Security Policy applied to iframes by Chrome.
Upvotes: 2