0

Is there a way to manipulate the loaded HTML or just run custom JavaScript over a loaded webpage?

I do not have access to the server I am loading from so I do not have that option.

1
  • loadUrl("javascript:blahblah"); Commented Jun 12, 2014 at 15:49

1 Answer 1

1

Call loadUrl("javascript:<your JS here>"); on the webview.

As of 4.4, you can also call the method evaluateJavascript(String script, ValueCallback<String> resultCallback) that will do a much nicer job. loadUrl will execute asynchronously with no return value (you have to jump through a lot of hoops in order to get a value back, including setting up a Java<->JS bridge and using thread synchronization in order to get a result). evaluateJavascript still executes asynchronously but the provided callback will be executed on the UI thread and is a much, much nicer way to go about things.

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

1 Comment

I didn't think getting a value back would even be possible. This is great, thanks!

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.