gpt4 book ai didi

gwt - 让浏览器在登录
中保存用户名/密码值?

转载 作者:行者123 更新时间:2023-12-01 19:18:02 27 4
gpt4 key购买 nike

我有一个 GWT 应用程序,并且需要用户登录表单。我想让浏览器保存用户的用户名和密码。我相信我需要为此使用一种“常规”形式(不是由 GWT 生成的形式)。所以我做了一个简单的表格:

<form id="myform">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Login" />
</form>

现在我想中断提交过程,获取用户名/密码,通过 RPC 登录,但让浏览器为用户保存这些字段的内容(如果他们愿意)。 GWT 开发板上有一些关于它的帖子,不确定哪一个有效,因为它们都不是开箱即用的。我认为它应该看起来像:

FormPanel form = FormPanel.wrap(Document.get().getElementById("myform"), false);
form.setAction("javascript:;");
form.addSubmitHandler(new SubmitHandler() {
public void onSubmit(SubmitEvent event) {
// Do my RPC call here?
// User should have been prompted to save password already now?
}
});

有人知道如何让它发挥作用吗?

最佳答案

这取决于您的表单 (myform) 的外观,因为每个浏览器都使用自己的启发式方法来发现具有要存储的凭据的潜在登录表单(例如,Chrome 需要标记 http://code.google.com/p/chromium/issues/detail?id=29513 中存在一个操作属性) )。因此,我们所做的就是在谷歌上搜索我们的应用程序必须支持的每个浏览器的记住凭据功能。结果是以下表单元素:

<form id="login-form" style="display:none" action="login">
<input type="text" tabindex="0" name="username" id="login-username">
<input type="password" tabindex="0" name="password" id="login-password">
<input style="position: absolute; left: -9999px; width: 1px; height: 1px;" type="submit">
</form>

可能也适合您。

编辑

这是一个适合我的示例(仅尝试过 FF 版本 14.x)。不要忘记从表单标记中删除 display:none

public class Starter implements EntryPoint {

private static final String FORM_ID = "login-form";
private static final String USER_ID = "login-username";
private static final String PASSWORD_ID = "login-password";

@Override
public void onModuleLoad() {
injectLoginFunction();
TextBox fUsername = TextBox.wrap(DOM.getElementById(USER_ID));
fUsername.setStyleName("gwt-TextBox");
PasswordTextBox fPassword = PasswordTextBox.wrap(DOM.getElementById(PASSWORD_ID));
fPassword.setStyleName("gwt-PasswordTextBox");
FormPanel fLoginForm = FormPanel.wrap(DOM.getElementById(FORM_ID), false);
fLoginForm.setAction("");
fLoginForm.addSubmitHandler(new SubmitHandler() {

@Override
public void onSubmit(SubmitEvent event) {
Window.alert("test");
}
});
fLoginForm.getElement().setAttribute("onsubmit", "login();return false;");
}

private static void doLogin() {
Window.alert("test");
}

private static native void injectLoginFunction() /*-{
$wnd.login = function() {
@test.client.Starter::doLogin()();
};
}-*/;
}

关于gwt - 让浏览器在登录 <form> 中保存用户名/密码值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2778350/

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