0

Im working on an epub reader for android platform. Not me started the project i just continue it so i have tons of code to get in to it.

My question is simple:

Is there a way in android to apply javascript to my html content inside my webView ?

I would like to make the html's font-size smaller or bigger by clicking a button for example... So users could modify font-size inside the webView.

Is there a way to achiev this ?

Any suggestions will be appreciated!

Thanks,

2 Answers 2

1

Is there a way in android to apply javascript to my html content inside my webView ?

Given a WebView object named wv, execute:

wv.loadUrl("javascript:..."); 

where the ... is the source code of the JavaScript to execute inside the context of the presently-displayed Web page. This is the same syntax used by bookmarklets in desktop browsers.

Note that you will also need to enable JavaScript in the first place, as described in nicholas.hauschild's answer.

Sign up to request clarification or add additional context in comments.

2 Comments

And how can i properly use "" this mark inside my String for javascript ? Because if i start with "javascript:" there will be other " marks inside my javascript and it became mixed up with the string if you know what i mean...
@AdamVarhegyi: In Java, you escape embedded quotation marks with backslashes: javacoffeebreak.com/faq/faq0050.html
1

Javascript is disabled by default on WebView's.

To enable javascript in a WebView, you need to first get a hold of the WebView's WebSettings member. This can be done via a call to getWebSettings() on your WebView.

Once you have your WebSettings, you can call setJavaScriptEnabled(true) on it.

WebView webView = getWebView(); WebSettings webSettings = webView.getWebSettings(); webSettings.setJavaScriptEnabled(true); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.