开发者

Only one javascript alert in Android WebView, then it stops responding

开发者 https://www.devze.com 2023-03-13 21:57 出处:网络
I set up a javascript alert() handler in a WebChromeClient for an embedded WebView: @Override public boolean onJsAlert(WebView view, String url, String message, final android.we开发者_JS百科bkit.JsRe

I set up a javascript alert() handler in a WebChromeClient for an embedded WebView:

@Override
public boolean onJsAlert(WebView view, String url, String message, final android.we开发者_JS百科bkit.JsResult result)  
{
  Log.d("alert", message);
  Toast.makeText(activity.getApplicationContext(), message, 3000).show();
  return true;
};

Unfortunately, this only shows a popup toast once, then the WebView stops responding to any events. I can't even use my menu command to load another page. I don't see errors in LogCat, what could be the problem here?


You need to invoke cancel() or confirm() on the JsResult result parameter.


add this

        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            result.confirm();
            Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();
            return true;
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消