- -
1.img标签上添加onerror事件时,报错:
Refused to execute inline event handler because it violates the following Content Security Policy directive: “default-src ‘self’ data: gap: https://ssl.gstatic.com ‘unsafe-eval’”. Note that ‘script-src’ was not explicitly set, so ‘default-src’ is used as a fallback.
“, source: file:///android_asset/www/index.html (41)
解决办法:
将index.html顶端的
注释掉
2.开启应用的时候报错Application error : the connection to the server was unsuccessful
这个错误一般出现在启动页面加载数据时间过长
所以首先你需要在config.xml修改加载超时时长:
<!--默认值为10000 单位毫秒-->
<preference name="LoadUrlTimeoutValue" value="50000"></preference>
然后尽量减少引用网络js,能下载为本地的都下载下来放到项目里
不能下载的放到使用页面加载:
//以加载百度地图js为例
//声明方法
loadjs = function (src, func) {
//判断这个js文件存在直接执行回调
var scripts = document.getElementsByTagName('script');
for (i in scripts)
if (scripts[i].src == src)
return func();
if (typeof func != 'function') {
console.log('param 2 is not a function!!');
return false;
}
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
var head = document.getElementsByTagName('head').item();
head.appendChild(script);
script.onload = function () {
func();
}
}
//调用
loadjs('http://api.map.baidu.com/getscript?v=2.0&ak=t8zuH8VGAlkVHtn28RY4ens1tszPhFEv&services=&t=20160804144823', function () {
//这里写加载完成后执行的代码
}
});
最后把首页要从后台拉取数据的代码都写到deviceready事件中.代码如下:
//这个事件触发时机为应用与手机连接初始化完成后
document.addEventListener("deviceready", function () {
//执行的代码
}, false);
后续陆续添加