Cordova InAppBrowser loaderror事件未针对错误500触发 [英] Cordova InAppBrowser loaderror event not firing for Error 500
问题描述
我在InAppBrowser中遇到问题.我正在尝试捕获可能来自正在加载的网站的错误,而我正在通过错误的.htaccess进行模拟,该错误会产生错误500.
I have an issue with InAppBrowser. I am trying to catch errors that might come from the website I'm loading and I'm simulating this by a faulty .htaccess, which produces an error 500.
我有以下代码:
ref = cordova.InAppBrowser.open($openuri, '_blank', 'location=no,toolbar=no,zoom=no,enableviewportscale=no,disallowoverscroll=no');
ref.addEventListener("loadstop",function() {
.....
});
ref.addEventListener("loaderror",function() {
alert('Toot');
});
ref.addEventListener('loadstart', function(event) {
.....
});
网站正在打开,所有"loadstop"和"loadstart"事件均正常运行.但是,当我故意使页面返回错误500"时,则不会触发"loaderror"事件.
The website is opening and all the "loadstop" and "loadstart" events work correctly. However, when I deliberately make the page return an "error 500", the event "loaderror" is not firing.
它确实会引发其他错误,例如电话上没有互联网时.
It does fire for other errors - like when there is no internet on the phone.
任何关于为什么发生这种情况的想法都受到高度赞赏.
Any ideas as to why this is happening are highly appreciated.
推荐答案
查看Android的InAppBrowser插件代码,它内部使用onReceivedError
方法处理loaderror
事件.所以我从Webview的角度看了这个问题,偶然发现了这个链接- https://code.google.com/p/android/issues/detail?id=968 ,其中指出onReceivedError
函数并非旨在捕获HTTP错误.
Looking at InAppBrowser Plugin code for Android, it interally uses onReceivedError
method for handling loaderror
event. So i looked at this issue from webview perspective and stumbled on this link - https://code.google.com/p/android/issues/detail?id=968 which states that the onReceivedError
function is not meant to catch HTTP errors.
对于HTTP错误处理,我们可能必须使用onReceivedHttpError
函数,该函数不属于插件.我希望这对为什么不起作用是有道理的.
For HTTP error handling, we may have to use onReceivedHttpError
function which is not part of the plugin. I hope it makes sense as to why this is not working.
这篇关于Cordova InAppBrowser loaderror事件未针对错误500触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!