如何在WebView组件中检索Javascript函数值 [英] How to retrieve Javascript function value in webview component

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

问题描述

如何从随Webview组件一起加载的网页中检索Javascript函数值?

How can I retrieve the Javascript 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对象注入Web页面,则可以设置另一个函数,该函数调用所需的函数并通过对注入的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组件中检索Javascript函数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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