有个问题,半天解决不了,希望万能的 v 友们来帮助帮助俺!
需求是这样的,在网站的一个页面中嵌入一个 iframe ,这个 iframe 指向另外一个网站(一个 jupyter 的 notebook )。在 safari 中访问没有问题,在 chrome 和 Firefox 中访问发现由于 CSP 的原因禁止。
我找到了这个网站(content-security-policy)[http://content-security-policy.com/],然后发现child-src字段是 CSP Level2 的规范,被 Chrome 40+和 Firefox 45+支持,这个字段就是定义 iframe 允许的源。于是我在 jupyter notebook 的响应头中添加了child-src: '*',然后 Firefox 可以访问了,但是 Chrome 还不可以!
我的 Chrome 版本是 49.0.
Chrome 报的错误是:
Refused to display 'http://127.0.0.1:8888/notebooks/2/2.ipynb' in a frame
because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".