frame報錯 Failed to set the 'href' property on 'Location': The current window does not have permission to navigate the target frame to...
阿新 • • 發佈:2020-12-22
之所以報這個錯的原因是因為你巢狀在frame中的網頁,居然檢視幹掉現在連結,重新開一個視窗,為了防止xss攻擊,frame表示我不同意堅決不同意
iframe預設情況下:
在html5頁面中,可以使用iframe的sandbox屬性,<iframe src="https://wx.tenpay.com?prepay_id=11111">如果未新增sandbox屬性,
或者添加了sandbox但是後面不加任何值,就代表採用預設的安全策略,
即:iframe的頁面將會被當做一個獨自的源,同時不能提交表單,以及執行javascript指令碼,也不能讓包含iframe的父頁面導航到其他地方,所有的外掛,
如flash,applet等也全部不能起作用。簡單說iframe就只剩下一個展示的功能,
正如他的名字一樣,所有的內容都被放入了一個單獨的沙盒。
sandbox包含的屬性及作用:
allow-forms 允許進行提交表單 allow-scripts 執行執行指令碼 allow-same-origin 允許同域請求,比如ajax,storage allow-top-navigation 允許iframe能夠主導window.top進行頁面跳轉 allow-popups 允許iframe中彈出新視窗,比如,window.open,target=”_blank” allow-pointer-lock 在iframe中可以鎖定滑鼠,主要和滑鼠鎖定有關
在iframe加上這個程式碼之後sandbox="allow-scripts allow-top-navigation allow-same-origin"只能解決巢狀頁面在本頁面本視窗跳轉頁面的情況,不能解決在frame中新開視窗的問題,
所以,我們讓巢狀iframe不新開視窗,在本頁面重新整理解決
點贊