Notification in embedded webview

When embedding a WebView in an application and loading html pages in it, JavaScripts alert () does not work. Give me an example pls

+3
source share
1 answer

By default WebChromeClient, the built-in browser will discard javascript warnings, you must override the implementation with WebChromeClientyour own version, this will also allow you to create your own custom warnings instead of the standard ones by default:

browser.setWebChromeClient(new MyWebChromeClient());

...

final class MyWebChromeClient extends WebChromeClient {
    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
        Log.d(LOG_TAG, message);
        new AlertDialog.Builder(view.getContext()).setMessage(message).setCancelable(true).show();
        result.confirm();
        return true;
    }
}
+14
source

Source: https://habr.com/ru/post/1748635/


All Articles