WebView blocking pop up windows?

前端 未结 2 1941
太阳男子
太阳男子 2021-01-03 09:41

I\'m using WebView to browse pesopay.com and it works properly, except when I pressed the submit button. Using internet browsers like Google Chrome will show a

相关标签:
2条回答
  • 2021-01-03 10:17

    The function which is responsible for dialogs in Webview is onJsAlert of WebChromeClient.

    Here is sample code

      public class MyWebChromeClient extends WebChromeClient {
        @Override
        public boolean onJsAlert(WebView view, String url, String message, JsResult jsResult) {
            // you can create your own dialog here or just return true for no pop up. 
            return true;
        }
    }
    

    and add this to your webview:

    MyWebChromeClient myWebChromeClient = new MyWebChromeClient();
    webView.setWebChromeClient(myWebChromeClient);
    
    0 讨论(0)
  • 2021-01-03 10:27

    If i am getting right , you need to use JavaScriptInterface for calling JavaScript function from Android.

    Check this link which may help you :

    http://www.codeproject.com/Articles/392603/Android-addJavaScriptInterface

    Or check some websettings : http://developer.android.com/reference/android/webkit/WebSettings.html#setSupportMultipleWindows%28boolean

    try to put this code in onCreate()

            webView.getSettings().setPluginsEnabled(true);
            webView.getSettings().setAllowFileAccess(true);
            webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    
    0 讨论(0)
提交回复
热议问题