开发者

Pulling a single variable off a webview in android?

I need to pull a value from a hidden div tag when using a webview. I have turned on javascript in my webvie开发者_运维知识库w activity but its not liking the "". HOW can I achieve my goal?

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;
  }
 }


Here's a short example of how to inject Javascript into a WebView.

If you actually want to get the value and use it in your Java code, you're going to have to register a JavascriptInterface like in this example - extracting HTML from a WebView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜