Zacharias Manuel
Zacharias Manuel

Reputation: 9013

Webview not loading javascript

I have loaded an html to the webview. I want to increase the font size of the p tag dynamically. For that I made a javascript and loaded after loading the html. But it is not working. What may be the problem??

Thanks in advance

mWebView.getSettings().setJavaScriptEnabled(true);

    mWebView.setWebViewClient(new WebViewClient() {
        public void onPageFinished(WebView view, String url) {
            String javascript="all_paras    =   document.getElementsByTagName('p');\n";
            javascript=javascript+"for(i=0;i<all_paras.length;i++) {all_paras[i].style.fontSize = '30px';}";
            mWebView.loadUrl("javascript:(" + javascript + ")()"); 
            System.out.println("Script executed..");
        }
    });

Upvotes: 1

Views: 361

Answers (1)

Zacharias Manuel
Zacharias Manuel

Reputation: 9013

Got the answer... Problem was with the syntax of javascript... Working code is

String javascript="function() {all_paras    =   document.getElementsByTagName('p');\n";
            javascript=javascript+"for(i=0;i<all_paras.length;i++) {all_paras[i].style.fontSize = '30px';}}";

Upvotes: 1

Related Questions