如何在webview组件中检索java脚本函数值 [英] How to retrieve java script function value in webview component
问题描述
如何从加载了webview组件的网页中检索java脚本函数值?
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()$ c $将Java对象注入网页c>,您可以设置另一个调用所需函数的函数,并通过调用注入的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.
这篇关于如何在webview组件中检索java脚本函数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!