cordova6.2中inAppBrowser插件的loaderror部分错误代码

Plugin API inAppBrowser for Cordova 6.2 loaderror Partial error code :

测试中只找到了以下常用的3个,官方并没有给出所有:

code:1001,message:The request timed out
code:1009,message:The Internet connection appears to be offline
code:102,message:Frame load interrupted

用法:

用检测是否要关闭这个内置的browser,比如apple设备打开itunes商店地址的时候会调用itunes应用,这是会切换出去。当你返回时这个browser就会留下一个白屏’loaderror’。这或许是一个bug!已提交官方:http://www.mail-archive.com/issues@cordova.apache.org/msg67410.html

我试着尝试使用事件Events的pause和resume来解决这个问题,发现每当打开自身的browser的时候就会触发这个事件,切到itunes时又会触发这个事件,不能够完美解决这个问题!

var ref = cordova.InAppBrowser.open('http://jeeinn.com', "_blank", 'location=yes');
ref.addEventListener('loaderror',function(e){
  //alert(e.code+':'+e.message);
  if(e.code=='-1001') alert('请求超时');//注意①
  if(e.code=='-1009') alert('请检查网络');
  //加载时被打断,例如进入系统的AppStore
  //if(e.code==102)//注意②
  ref.close();
}

注意:
①这里的code是字符串类型,这个问题让我测试了好几遍;

②这里的code是数字型,我真是醉了

希望大家能在评论中添加更多错误代码。

I hope you can add more error code in the comments.

Author: thinkwei

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注