Jupyter Notebook:指向本地存储的pdf文档的超链接在Chrome中停止工作 [英] Jupyter notebook: hyperlink to locally stored pdf docs stopped working in Chrome

查看:143
本文介绍了Jupyter Notebook:指向本地存储的pdf文档的超链接在Chrome中停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的Jupyter笔记本,在许多笔记本中,我都有指向本地存储的pdf文档的超链接.不久前,这些链接在我的Chrome中的iMac上不再起作用.单击链接时,将打开一个具有正确地址的新选项卡,但页面仅为黑色.当我在使用完全相同的Jupyter笔记本的MacBook上执行此操作时,它可以正常工作. MacBook上的环境与iMac上的环境基本相同.一切都是最新的.我正在将Anaconda用于Python和Jupyter.

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.

当在iMac上发生此问题时,在Chrome中查看控制台时,出现以下错误消息: 无法加载' http://localhost:8888/files/Cookbooks/Git%20%26%20GitHub/books/Pro_Git.pdf "作为插件,因为插件要加载到其中的框架已沙箱化.

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.

当我在Safari或Firefox上打开Jupyter笔记本时,超链接工作正常. Chrome是我的默认浏览器,我希望对此进行修复.我不是很熟练,也无法在互联网上找到任何解决方案.帮助将不胜感激.

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.

推荐答案

一个简单的解决方法是使用<embed>元素而不是<iframe>.

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)

要显示您的PDF,请使用以下内容:

To display your PDF, use the following:

pdf('./data-ref/pluto_datadictionary.pdf')

注意:pdf文件应存储在您的jupyter笔记本旁边

Note: the pdf file should be stored next to your jupyter notebook

最初的iframe问题与所适用的内容安全政策有关通过Chrome浏览到iframe

The original iframe issue is related to the Content Security Policy applied to iframes by Chrome.

这篇关于Jupyter Notebook:指向本地存储的pdf文档的超链接在Chrome中停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆