简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM