frame报错 Failed to set the 'href' property on 'Location': The current window does not have permission to navigate the target frame to...

之所以报这个错的原因是因为你嵌套在iframe中的网页,居然试图干掉现在链接,重新开一个窗口,为了防止xss攻击,iframe表示我不同意坚决不同意

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不新开窗口,在本页面刷新解决

点赞👍+关注我吧~

成为更好的自己

 

posted @ 2020-12-22 12:06  文学少女  阅读(6629)  评论(0编辑  收藏  举报