【发布时间】:2016-05-27 22:01:59
【问题描述】:
我有 cordova 应用程序,它在运行时加载所需的 corretc html 文件,当作为应用程序启动时它工作正常。是否可以在 chrome 中测试此功能,因为这会大大加快开发速度。
首先,我使用
从 cmd 行打开了 chromeC:\installationpath\chrome.exe --allow-file-access-from-files
正如here 所说,但这给了我同样的错误:
XMLHttpRequest 无法加载 文件:///C:/myworkdir/myfile.html。叉 源请求仅支持协议方案:http、data、 chrome, chrome-extension, https, chrome-extension-resource.
并且还为 jquery mobile 添加了这个:
$(document).bind('mobileinit',function(){
$.support.cors = true;
$.mobile.allowCrossDomainPages = true;
$.mobile.changePage.defaults.changeHash = false;
$.mobile.hashListeningEnabled = false;
$.mobile.pushStateEnabled = false;
});
有没有办法解决这个问题,或者我应该直接在应用程序上使用chrome://inpsect 在构建时进行调试
如果它有助于应用程序中的功能:
function includePage (file, callback){
$.get(appFiles + 'layout/' + file.name + '.html')
.success(function(html) {
$('#AppBody').append(html);
if(file.active){
$.mobile.changePage(file.id,{changeHash: false});
}
if(callback !== undefined || callback !== null){
callback();
}
});
};
此功能在我的应用上运行良好
【问题讨论】:
-
可能相关,但可能仅适用于扩展程序,而不适用于应用程序:stackoverflow.com/questions/17155916/…
标签: cordova google-chrome google-chrome-extension cors same-origin-policy