technical po
technical po

Reputation: 29

Android WebView with JavaScript enabled

In a WebView in my app I cannot run JavaScript. I tried many ways and searched many Stackoverflow pages to find the answer. It cannot even show me a simple alert message.

Here's my code :

WebView webView = (WebView) findViewById(R.id.wv_webviewac);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.loadUrl(url);

Eeverything is fine in the browser but in a WebView it doesn't work.

Upvotes: 2

Views: 1716

Answers (1)

Sebin Sunny
Sebin Sunny

Reputation: 1803

this will solve the problem

 mWebView = (WebView) findViewById(R.id.activity_main_webview);
            WebSettings webSettings = mWebView.getSettings();
            webSettings.setJavaScriptEnabled(true);
            mWebView.loadUrl("https://syllabkerala.in");
            mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    //hide loading image
                    findViewById(R.id.progressBar1).setVisibility(View.GONE);
                    //show webview
                    findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
                }
            });

Upvotes: 1

Related Questions