如何中检索中的WebView组件Java脚本函数值脚本、函数、组件、WebView

2023-09-06 17:45:20 作者:倾城一笑

我如何检索网页中的Java脚本函数值加载withing一个web视图组件??

How can I retrieve the java script function value from a web page loaded withing a webview component??

推荐答案

您不能直接。

您可以通过调用使用loadURL Javascript函数(JavaScript的:...),其中 ... 是函数调用。但是,你不能因此这种方式。

You can call the Javascript function via loadUrl("javascript:..."), where ... is your function call. However, you cannot get a result this way.

如果您通过 addJavascriptInterface注入一个Java对象到网页(),你可以设置一个名为你想要的功能,并通过调用返回一个值,另一个函数所注入的Java对象。这只是工作,如果你可以修改网页,但。

If you inject a Java object into the Web page via addJavascriptInterface(), you could set up another function that called the function you want and returns that value via a call to the injected Java object. That only works if you can modify the Web page, though.