我收到錯誤:Refused to frame 'http://localhost:8888/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".當嘗試從包含另一個本地 HTML 文件的 iframe 的本地 HTML 文件創(chuàng)建 iframe 時。例如test-outer.html:<!DOCTYPE html><html><body><iframe sandbox="allow-scripts" id="0" src="./test-inner.html" width="100" height="100" frameborder="0"></iframe></body></html>使用 Jupyter Notebook Python 代碼:from IPython.display import IFrameIFrame(src='test-outer.html', width=200, height=200)test-inner.html可以包含任何東西。test-outer.html在單獨的瀏覽器選項卡上完美加載。問題在于將其加載到 Jupyter Notebook 中。
1 回答

瀟瀟雨雨
TA貢獻1833條經驗 獲得超4個贊
雖然這是一個老問題,但是對新求知者有所幫助。
您需要在 jupyter_notebook_config.py 中添加標頭
c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': "frame-ancestors self https://my-website-url.com/jupyter "}}
https://my-website-url.com/jupyter
是您在其中加載 jupyter 筆記本的 url iFrame
。
這適用于 Firefox 和 Chrome。未在 Safari 中測試。
添加回答
舉報
0/150
提交
取消