我正在我的应用程序中加载一个子浏览器,当我点击一个链接时,onLocationChange被调用两次。关于为什么会发生这种情况的任何建议?
javascrpt代码是
function openAppTerms() {
var options = {
'showLocationBar' : true,
'pageDesc':'Application Terms'
};
window.plugins.childBrowser.onLocationChange=function(newurl){
if(newurl == "no") {
}
else if(newurl.indexOf("mailto")>=0 ){
var succcallback = function(result) {
//alert("Mail sent");
window.plugins.childBrowser.close();
};
var errorcallback = function(e) {
//alert("error:" + e);
window.plugins.childBrowser.close();
};
window.plugins.webintent.sendEmail({
mailSubject : 'CPS Mobile App',
mailRecepients: 'UnisysPrivacyOffice@Unisys.com',
//mailBody: href1
mailBody: ' '
}, succcallback, errorcallback);
window.plugins.childBrowser.close();
}
else {
alert(newurl);
}
};
window.plugins.childBrowser.showStaticPage("app_terms.html",options);
}
,java代码是:
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
String newloc;
if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("mailto:")) {
newloc = url;
}
else
{ newloc = "no";}
try {
JSONObject obj = new JSONObject();
obj.put("type", LOCATION_CHANGED_EVENT);
obj.put("location", newloc);
sendUpdate(obj, true);
} catch (JSONException e) {
Log.d("ChildBrowser", "This should never happen");
}
}
答案 0 :(得分:0)
我相信super.onPageStarted(view,url,favicon);是这样的原因。