使用通过EditText获得的变量向Webview发送javascript命令

Send a javascript command to a Webview using variables gotten with an EditText

本文关键字:变量 Webview 发送 命令 javascript EditText      更新时间:2023-09-26

我正在创建一个简单的网络应用程序,用户每次打开网站时都不必输入凭据(无法保存密码)。我设法找到了表单的字段和提交操作,当提交以下行时,可以通过Crome的控制台登录。

document.getElementById('zonePwd').value="Password"
document.getElementById('zoneId').value="Id"
GInterface.traiterEvenementValidation()

现在,在我的网络应用程序上,我想知道在用户用这两种信息填充对话框后,是否可以使用字符串做同样的事情。

如果我对不够清楚,一定要这么说

感谢

PS:我对JS 非常陌生

我建议您创建一个javascript函数,如:

function setCredentials(id, pass)
{
    document.getElementById('zonePwd').value=pass;
    document.getElementById('zoneId').value=id;
    GInterface.traiterEvenementValidation();
}

然后从你的应用程序代码

String id = "myid"; //Get val from the dialog
String pass = "mypass"; //Get val from the dialog
webview.loadUrl("javascript:setCredentials('"+id+"','"+pass+"')");

希望它能有所帮助;)