我有 2 个文件:桌面上的 file.html
和本地主机上的 local.html
。是否可以让文件访问本地主机?目前,我在 Chrome 上遇到此错误:
Uncaught SecurityError: Blocked a frame with origin "null" from accessing a frame with origin "http://localhost". The frame requesting access has a protocol of "file", the frame being accessed has a protocol of "http". Protocols must match.
首选 .htaccess 解决方案,但 Header set Access-Control-Allow-Origin *
不起作用。
最佳答案
你不能这么做。 (除非使用 JSONP 完全绕过策略)
您应该完全避免 file://
。
关于javascript - 让文件://access http://localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34996836/