今天有个需求是在 app 中获取 webview 里用户在输入框中输入的文字,请问有什么实现方式或者思路吗?求教
![]() | 1 superleexpert 2015-12-22 17:31:27 +08:00 通过 WEB 端 JS 回调来传递输入的信息。 |
![]() | 2 vincentxue 2015-12-22 17:45:33 +08:00 一般 input 都设了 name 或者 id 吧,调 JS 就行. document.getElementById('id').value id 是你 HTML 里 textField 的 id. 没测试过,理论上应该是可行的。 |
![]() | 3 chengkai1853 2015-12-22 17:54:04 +08:00 1 楼正解 |
![]() | 4 qiayue PRO iOS 的话,你可以直接注册一个 js 函数(假设叫 getName ), js 中用 nativ.getName() 可以调用你的函数 |
![]() | 5 Keita1314 2015-12-22 18:03:24 +08:00 Javascript:document.getElementById('id').value OC:UIWebView stringByEvaluatingJavascriptFromString |
6 iamjjh OP |
7 em70 2015-12-22 19:37:12 +08:00 via iPhone 对网页有控制权吗?有就好办,点击按键把输入框内容做成 url 发出一个 http 请求, webbview 拦截请求获得 url 从中分析出输入内容即可,非常稳定 |