0
我正在我的應用程序中加載一個childbrowser,當我點擊一個鏈接時,onLocationChange被調用兩次。有關爲什麼會發生這種情況的任onLocationChanged調用兩次
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: '[email protected]',
//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");
}
}
我試着刪除那段代碼。但它力量有所作爲。 – Khush 2012-03-06 05:59:49