跨域问题(iframe)记录

Posted haliofwu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了跨域问题(iframe)记录相关的知识,希望对你有一定的参考价值。

an ancestor violates the following Content Security Policy directive: “frame-ancestors ‘self’

场景描述:
iframe内嵌jupyter页面;
本地安装jupyter,命令行jupyter notebook开启,在本地开发环境下的页面内嵌入iframe

<div id="left">
    <button class="button-test" >测试</button>
</div>
<div id="right">
    <iframe id="nb-iframe" src="http://localhost:8888/notebooks/exp-2-Copy1%20(1).ipynb" style="width:800px;height:600px;"></iframe> 
    <!-- <iframe width="560" height="315"  src="https://www.youtube.com/embed/YOUR_VIDEO_CODE" frameborder="0" allowfullscreen></iframe> -->


</div>

<style>
*
    margin:0;
    padding:0;

 #left
     width:200px;
     height: 800px;
     background-color:#ccc;
     float:left;
 
 #right
     height: 800px;
     margin-left:200px;
     padding-left:20px;
 

.button-test
    padding-left:10px;
    padding-right:10px;
    background-color:aqua;
    border-radius: 4px;


</style>  

报错:

Refused to display ‘http://localhost:8888/notebooks/exp-2-Copy1%20(1).ipynb’ in a frame because an ancestor violates the following Content Security Policy directive: “frame-ancestors ‘self’”.

解决方法:

1.https://github.com/jupyter/tmpnb/issues/263
2.https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors

启动方式:

jupyter notebook –NotebookApp.tornado_settings=’“headers”:“Content-Security-Policy”:”frame-ancestors self http://localhost:8888 http://localhost:5000 http://127.0.0.1:5000 http://127.0.0.1:8888;” ’

再次嵌入ok了。

以上是关于跨域问题(iframe)记录的主要内容,如果未能解决你的问题,请参考以下文章

iframe跨域获取父页面url

用P3P header解决iframe跨域访问cookie

用P3P header解决iframe跨域访问cookie

用P3P header解决iframe跨域访问cookie

iframe与父页面之间通讯跨域问题

现开发项目遇见难题及解决方案记录