如何在 Webview Android 中执行按钮单击 [英] How to perform a button click inside a Webview Android

查看:21
本文介绍了如何在 Webview Android 中执行按钮单击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是创建了这个应用程序:

I simply created this app:

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WebView view = (WebView) findViewById(R.id.webView);
    WebSettings faller = view.getSettings();
   faller.setJavaScriptEnabled(true);
   view.loadUrl("http://catcheat.net/test/test.html");
    view.setWebViewClient(new WebViewClient());

}
} 

现在我想做的是在页面上显示的唯一按钮中以编程方式单击但我真的不知道该怎么做.我在这里阅读了所有类似的帖子,但没有人可以帮助我.

Now what I want to do is to click programmatically in the unique button that is displayed on the page But I really don't know how to do. I ve read every post like this here but nobody could help me.

这是 HTML 页面:

This is the HTML page:

<html>
<body>
<form name="pg_frm" method="post" action="https://www.paygol.com/pay" >
<input type="hidden" name="pg_serviceid" value="333818">
<input type="hidden" name="pg_currency" value="EUR">
<input type="hidden" name="pg_name" value="Donation">
<input type="hidden" name="pg_custom" value="">
<input type="hidden" name="pg_price" value="0.5">
<input type="hidden" name="pg_return_url" value="">
<input type="hidden" name="pg_cancel_url" value="">
<input type="image" name="pg_button" src="https://www.paygol.com/webapps /buttons/en/white.png" border="0" alt="Make payments with PayGol: the  easiest way!" title="Make payments with PayGol: the easiest way!" >    
</form> 
</body>
</html>

推荐答案

如果你的 Button 在你的 Html 页面中,那么你可以简单地运行 javaScript 代码来模拟这样的点击事件:

if your Button is in your Html page so you can simply run javaScript code to simulate click event like this:

view.loadUrl("javascript:clickFunction()"); 

您还需要在 Html 页面中定义 clickFunction:

also you need to define clickFunction in your Html page:

function clickFunction() {
    //click event
}

或者您也可以通过javascript添加上述功能:

or you can add above function by javascript too:

 view.loadUrl("javascript:clickFunction(){ //click event })()"); 

更新:

 <html>
 <head>
 <script>
 function clickFunction(){
      var form = document.getElementById("myform");
      form.submit();
 }
 </script>
 </head>
 <body>
 <form id="myform" name="pg_frm" method="post" action="https://www.paygol.com/pay" >
 <input type="hidden" name="pg_serviceid" value="333818">
 <input type="hidden" name="pg_currency" value="EUR">
 <input type="hidden" name="pg_name" value="Donation">   
 <input type="hidden" name="pg_custom" value="">
 <input type="hidden" name="pg_price" value="0.5">
 <input type="hidden" name="pg_return_url" value="">
 <input type="hidden" name="pg_cancel_url" value="">
 <input type="image" name="pg_button" src="https://www.paygol.com/webapps /buttons/en/white.png" border="0" alt="Make payments with PayGol: the  easiest way!" title="Make payments with PayGol: the easiest way!" >    
 </form> 
 </body>
 </html>

这篇关于如何在 Webview Android 中执行按钮单击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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