1. 為什么需要解決chrome瀏覽器跨域的問題?
基於Hybird App的H5部分,可以直接打包進apk或者ipa包中,在開發過程中也不需要放置到臨時搭建的服務器上,直接在本地打開html靜態頁面,打開后會頁面的域名是file
file域名下的文件發送http或https也是需要跨域的(跨域這里不細說)
2. 解決Chrome78以上跨域失效問題
Chrome 46版本后,解決跨域問題需要修改快捷方式的目標(修改方式百度),在快捷方式目標路徑后面添加
-args --disable-web-security
但是78版本之后 必須 添加跨域后放置用戶數據的文件夾路徑,在快捷方式目標路徑后面添加
-args --disable-web-security --user-data-dir=C:\Users\xiaoxin.qiao\AppData\Local\Google\Chrome\MyChromeDevUserData --ignore-certificate-errors
全部的為:
C:\Users\xiaoxin.qiao\AppData\Local\Google\Chrome\Application\chrome.exe -args --disable-web-security --user-data-dir=C:\Users\xiaoxin.qiao\AppData\Local\Google\Chrome\MyChromeDevUserData --ignore-certificate-errors --allow-file-access-from-files