简体   繁体   English

Android - WebView中的Javascript

[英]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. 其中两个对我来说很有趣,但他们没有设置ID。 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? 现在 - 我可以注入HTML代码加载jQuery来获取这些元素,还是我必须遍历网站上的所有元素才能找到我真正需要的元素?

One approach is to use WebView.addJavascriptInterface to expose a Java interface to your JavaScript. 一种方法是使用WebView.addJavascriptInterface向您的JavaScript公开Java接口。 This lets your JavaScript call your Java object directly. 这使您的JavaScript可以直接调用Java对象。 Depending on your situation, this can be unsafe, especially if you don't control the JavaScript. 根据您的具体情况,这可能不安全,特别是如果您不控制JavaScript。

Injection will work too using WebView.loadUrl() , but depending on the complexity of your page (redirects, etc), that can be problematic as well. 注入也可以使用WebView.loadUrl() ,但是根据页面的复杂性(重定向等),这也可能有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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