gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:57:48 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com