android - 如何在 Webview Android 中执行按钮单击

标签 android button webview click

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

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());

}
} 

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

这是 HTML 页面:

<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 代码来模拟这样的点击事件:

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

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

function clickFunction() {
    //click event
}

或者你也可以通过 javascript 添加上面的函数:

 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>

关于android - 如何在 Webview Android 中执行按钮单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30113445/

相关文章:

java - 如何修改ListView的ArrayList,但ListView和ArrayList在不同的Activity中

android - ViewPager Adapter 类中的 Activity 布局元素

java - 学习重构代码: is there a short hand way of setting all buttons to have the same dimensions?

iphone - -drawRect : 中的可点击文本

android - 取消 Web View 中的文件上传

objective-c - void SendDelegateMessage(NSInvocation*) : delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:)

java - 为 webview 实现闪屏时出错

安卓蜂窝 : Fragment not able to start AsyncTask?

html - 通过单击背景 <image> 打开模式

android - 如果用户在设备中更改日期和时间,那么如何在 android 中获取当前日期和时间?