Android webview获取网页标题并展示、自定义(重写)网页的alert弹框

webView.setWebChromeClient(new WebChromeClient() {
//获取网页的标题
@Override
public void onReceivedTitle(WebView view, String title) {
    super.onReceivedTitle(view, title);
    setTitle(title);
}
//重写alert弹框
@Override
public boolean onJsAlert(WebView view, String url, final String message, JsResult result) {
    WjLog.d("main", "onJsAlert:" + message);
    runOnUiThread(new Runnable() {
            @Override
            public void run() {
                new AlertDialog.Builder(WebViewActivity.this)
                        .setTitle("提示")
                        .setMessage(message)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //webView.reload();//重写刷新页面
                    }
                }).show();
            }
        });
        result.confirm();//这里必须调用,否则页面会阻塞造成假死
        return true;
    }
});


若文章对您有帮助,帮忙点个赞!

0
0
发布时间 2020-09-09 23:31:36
0 条回复(回复会通过微信通知作者)
点击加载更多评论
登录 后再进行评论
(微信扫码即可登录,无需注册)