4

I have an app where my min API is 16, and I want to evaluate some javascript on a web view and when I have

mWebView.evaluateJavascript("(function()...)");

I get a compile error saying this is only available in API 19 and higher, so how can I evaluate javascript in a web view for the API below 19, I have but above code in a if statement for API 19 and above, but how can I do this in API below 19?

Thanks for the help

1 Answer 1

3

Before API 19, you have to use WebView.loadUrl() with the javaScript protocol to evaluate JavaScript within the currently loaded page:

String javaScript = // Some JavaScript code here

if (Build.VERSION.SDK_INT >= 19) {
    mWebView.evaluateJavascript(javaScript, null);
} else {
    mWebView.loadUrl("javascript:" + javaScript);
}
Sign up to request clarification or add additional context in comments.

1 Comment

How will you evaluate a js function with parameters? Something function example(a,b) { return (a+b); }

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.