![afecc3d2f2a5f4d6fd5dfcea511b11e4.png](https://img-blog.csdnimg.cn/img_convert/afecc3d2f2a5f4d6fd5dfcea511b11e4.png)
本地文件用浏览器打开是 file协议,file:///***.html如果有跨域请求,会在控制台报错
![d069517aafbce54534f7d858e56f1ffd.png](https://img-blog.csdnimg.cn/img_convert/d069517aafbce54534f7d858e56f1ffd.png)
Access to XMLHttpRequest at ‘file:///D:/getCompanyList’ from origin ‘null’ has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
以前很轻松解决了,这次发现尝试好几个办法都不行
解决方案:
方法一:配置快捷方式目标参数
找到谷歌浏览器快捷键-右键-属性-快捷方式-目标的后面输入空格再加–allow-file-access-from-files,再关闭所有chrome窗口,重启chrome,再通过快捷键打开的浏览器输入本地文件路径
注意:allow前面有两个“-”
![62391520b6d0718a065dafba3f97d417.png](https://img-blog.csdnimg.cn/img_convert/62391520b6d0718a065dafba3f97d417.png)
chrome版本使用场景: 80.0.3987.163(正式版本) (64 位)
![050aa7dc490d0248a40198155faacb30.png](https://img-blog.csdnimg.cn/img_convert/050aa7dc490d0248a40198155faacb30.png)
方法二:把目标的值可以通过cmd中敲命令
![ce00d95b18efdb7bdf61f5a19126aff8.png](https://img-blog.csdnimg.cn/img_convert/ce00d95b18efdb7bdf61f5a19126aff8.png)
方法三:新建bat文件
可以把在要敲的命令放进去新建一个bat文件里,双击就能打开chrome浏览器
![d5276c2ab45ddcf0de3875d8b7b7fa0f.png](https://img-blog.csdnimg.cn/img_convert/d5276c2ab45ddcf0de3875d8b7b7fa0f.png)
踩坑记录:
(1)目标在后面写 --disable-web-security 无效
(2)目标在后面写 --disable-web-security --user-data-dir 也无效
(3)目标在后面写 --args --disable-web-security --user-data-dir 也无效
Chromium命令行启动参数:https://code.google.com/archive/p/xiaody/wikis/ChromiumCommandLineSwitches.wiki更全面参数参考: http://peter.sh/experiments/chromium-command-line-switches/