使用webview时,我需要从隐藏的div标签中提取值。我在我的webview活动中打开了javascript但不喜欢“”。我如何实现目标?
public class buttonOne extends Activity{
WebView wb = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.buttons);
wb = new WebView(this);
wb.getSettings().setJavaScriptEnabled(true);
wb.setWebViewClient(new HelloWebViewClient());
wb.getSettings().setJavaScriptEnabled(true);
wb.loadUrl("http://ishopstark.com/mobileapp.php?category=1");
setContentView(wb);
}
private class HelloWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
<script type="text/javascript">
{
var varSendText = document.getElementById("sendtextcoupon").value;
}
</script>
return true;
}
}
答案 0 :(得分:8)
以下是如何inject Javascript into a WebView的简短示例。
如果你真的想要获取值并在Java代码中使用它,那么你将不得不注册一个JavascriptInterface,如本例所示 - extracting HTML from a WebView