karex
karex

Reputation: 217

Android - Javascript in WebView

I have a simple site where I have inputs. Two of them are interesting for me, but they haven't got id set. They have only name. And now - can I inject to HTML code loading of jQuery to get this elements or do I have to iterate over all elements at site in order to find those I really need?

Upvotes: 0

Views: 83

Answers (1)

dhaag23
dhaag23

Reputation: 6126

One approach is to use WebView.addJavascriptInterface to expose a Java interface to your JavaScript. This lets your JavaScript call your Java object directly. Depending on your situation, this can be unsafe, especially if you don't control the JavaScript.

Injection will work too using WebView.loadUrl(), but depending on the complexity of your page (redirects, etc), that can be problematic as well.

Upvotes: 2

Related Questions