|After the latest updated of the Android System Webview (52.0.2743.98) I noticed that javascript can't be executed withing the onJsAlert method.
|在最新更新的Android系统Webview(52.0.2743.98)之后,我注意到无法使用onJsAlert方法执行javascript。
More specifically the following piece of code stopped working after the latest update
更具体地说,以下代码在最新更新后停止工作
private class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());
return super.onJsAlert(view, url, message, result);
}
}
I have also checked that the interface has been set correctly
我还检查了界面设置是否正确
mWebView.setWebChromeClient(new MyWebChromeClient());
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new CustomInterface(), "CustomInterface");
Has anyone came across the same issue?
有人遇到过同样的问题吗?
1 个解决方案
#1
0
Th hint for the solution was given to me when I returned false for the onJAlert
当我为onJAlert返回false时,给出了解决方案的提示
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());
return false;
}
If the client returns true, WebView will assume that the client will handle the dialog. If the client returns false, it will continue execution. So by returning false I got a dialog box on my UI and when I pressed ok the javascript was executed. So I just called confirm from the JsResult which was like pressing the OK button
如果客户端返回true,则WebView将假定客户端将处理该对话框。如果客户端返回false,它将继续执行。因此,通过返回false,我的UI上有一个对话框,当我按下确定时,javascript被执行了。所以我刚刚从JsResult打电话确认,就像按下OK按钮一样
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());
return true;
}
#1
0
Th hint for the solution was given to me when I returned false for the onJAlert
当我为onJAlert返回false时,给出了解决方案的提示
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());
return false;
}
If the client returns true, WebView will assume that the client will handle the dialog. If the client returns false, it will continue execution. So by returning false I got a dialog box on my UI and when I pressed ok the javascript was executed. So I just called confirm from the JsResult which was like pressing the OK button
如果客户端返回true,则WebView将假定客户端将处理该对话框。如果客户端返回false,它将继续执行。因此,通过返回false,我的UI上有一个对话框,当我按下确定时,javascript被执行了。所以我刚刚从JsResult打电话确认,就像按下OK按钮一样
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
result.confirm();
view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());
return true;
}