Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

如何解决在chrome的无痕窗口下iframe中的页面直接使用localStorage导致的跨域异常

现在有一种用例,在一个域名为"https://xxx.yyy.com/#/hhh"的页面(下略为页面A)中使用一个iframe,其src指向"https://zzz.aaa.cn/index.html#/example"(下略为页面B),其中页面B的代码中使用了localStorage.getItem函数,使用chrome单独打开页面B或者在正常模式下打开页面A不会有任何报错,localStorage能正常读写,但是当我使用chrome的无痕窗口时,打开页面A就会报如下错误:

DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

,代码追踪显示显示是页面B使用了localStorage.getItem之后从页面B报出来的错误,单独打开页面B却不会有任何的报错,但是看起来又不像是跨域的问题,如果是跨域问题,那为什么唯独在chrome的无痕窗口中打开页面A会报这样的错误呢?页面B没有通过iframe进行过任何通信,页面A也没有操作iframe的DOM。请问这个问题的根源在于什么地方?要如何去解决?(不能要求用户修改chrome设置的前提下的解决方案)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...