1

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..");
        }
    });

1 Answer 1

1

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';}}";
Sign up to request clarification or add additional context in comments.

2 Comments

Err, it's the same is it not?
@funkybro: Sry.. I have editted the question. Use the answer. This is the correct one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.