1. 程式人生 > >跨域問題(iframe)記錄

跨域問題(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’”.

解決方法:

啟動方式:

再次嵌入ok了。