【问题标题】:Allow chrome to access local files for cordova testing允许 chrome 访问本地文件以进行 cordova 测试
【发布时间】:2016-05-27 22:01:59
【问题描述】:

我有 cordova 应用程序,它在运行时加载所需的 corretc html 文件,当作为应用程序启动时它工作正常。是否可以在 chrome 中测试此功能,因为这会大大加快开发速度。

首先,我使用

从 cmd 行打开了 chrome

C:\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(); 
        }
    });
};

此功能在我的应用上运行良好

【问题讨论】:

标签: cordova google-chrome google-chrome-extension cors same-origin-policy


【解决方案1】:

试试:

C:\installationpath\chrome.exe --allow-file-access-from-files --disable-web-security

【讨论】:

    猜你喜欢
    • 2014-01-11
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多