我正在尝试在webview中加载URL但是它没有调用shouldOverrideUrlLoading
webview.setWebViewClient(new HelloWebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
// webview.loadUrl("http://www.google.com");
// webview.loadUrl("http://www.androidexample.com/media/webview/login.html");
webview.loadUrl(URL_TO_LOAD);
webview.getSettings().setDomStorageEnabled(true);
webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webview.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
Log.d("URL!!!! ", url);
Log.d("message!!!! ", message);
// Log.d("URL!!!! ", url);
return super.onJsAlert(view, url, message, result);
// System.out.println("url = " + url);
}
});
这是我的班级
private class HelloWebViewClient extends WebViewClient {
ProgressDialog progressDialog;
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (progressDialog == null) {
// in standard case YourActivity.this
progressDialog = new ProgressDialog(TestWv.this);
progressDialog.setMessage("Loading...");
progressDialog.show();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
System.out.println("onPageFinished = ");
try {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
progressDialog = null;
}
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
如果我通过google.com它正常工作...它正常工作......但如果我通过我的URL它不会调用shouldOverrideUrlLoading或onPageFinished方法..问题应该是什么?
请帮助......
答案 0 :(得分:0)
尝试通过以下方式禁用dom存储:
webview.getSettings().setDomStorageEnabled(false);
,看看是否应该立即调用shouldOverrideUrlLoading。