如何在webview组件中检索java脚本函数值 [英] How to retrieve java script function value in webview component

查看:63
本文介绍了如何在webview组件中检索java脚本函数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从加载了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(),您可以设置另一个调用所需函数的函数,并通过调用注入的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆