如何在Webview Android内执行按钮单击

如何在Webview Android内执行按钮单击,第1张

概述我只是创建了这个应用程序 public class MainActivity extends ActionBarActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a 我只是创建了这个应用程序

public class MainActivity extends ActionBaractivity {@OverrIDeprotected 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>
总结

以上是内存溢出为你收集整理的如何在Webview Android内执行按钮单击全部内容,希望文章能够帮你解决如何在Webview Android内执行按钮单击所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1122349.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存