配置chrome支持本地(file協議)ajax請求 網址:配置chrome支持本地(file協議)ajax請求
將html代碼拖拽進入chrome通過file協議瀏覽時,發送的ajax請求本地文件,會報跨域錯誤。
XMLHttpRequest cannot load file:///E:/webs/extJS/ext-3.3.0/examples/csdn/combobox.txt?_dc=1414738973999.
Cross origin requests are only supported for protocol schemes: http, data,
chrome-extension, https, chrome-extension-resource.
解決辦法是給chrome添加啟動參數:--allow-file-access-from-files ,這樣本地ajax請求就不會報跨域錯誤了。
(注意如果給chrome添加多個啟動參數,每個啟動參數“--”之前要有空格隔開,
如"C:\Program Files\Google\Chrome\Application\chrome.exe" --enable-file-cookies --allow-file-access-from-files)
如何添加chrome啟動參數以便支持file協議下的ajax請求,
具體看這個:chrome無法保存本地設置cookie解決辦法
添加了--allow-file-access-from-files啟動參數后,
還可以解決本地file加載文件,導致iframe和父頁無法相互訪問,
window.open打開的頁面使用opener為null的問題,參考:chrome本地測試訪問iframe,parent,opener null解決辦法
....................................................................................................................................................來源於互聯網