Search code examples
androidwebviewpopup

PopUp screen not opening In webview?


I am Currently working with webview in which Javascript popup is created when some button is clicked in webview. But it is not opening in my Webview.

My code is Here:

wvPayements = (WebView) view.findViewById(R.id.wvPaymentsPage);
    wvPayements.getSettings().setLoadWithOverviewMode(true);
    wvPayements.getSettings().setUseWideViewPort(true);
    wvPayements.getSettings().setSupportZoom(true);
    wvPayements.getSettings().setAllowFileAccess(true);
    wvPayements.getSettings().setJavaScriptEnabled(true);
    wvPayements.getSettings()
            .setJavaScriptCanOpenWindowsAutomatically(true);
    wvPayements.getSettings().setBuiltInZoomControls(true);
    wvPayements.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, final String url) {
            dialog.cancel();
        }
    });
     wvPayements
     .loadUrl("http://192.168.0.114/Parch_ws/testalert.html");

Solution

  • You have to use WebChromeClient for your purpose:

    One should use a WebChromeClient to get these alerts and the functionality can be overwritten using theonJsAlert() method. Hope this helps!

    WebView wv=new WebView(this); 
    wv.setWebChromeClient(new WebChromeClient() {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            //Required functionality here
            return super.onJsAlert(view, url, message, result);
        }
    });
    

    Source: https://issuetracker.google.com/issues/36905249#comment11