是否可以在 GXT 中实现跨浏览器用户名/密码自动完成?

发布于 2024-08-01 19:55:39 字数 1877 浏览 4 评论 0原文

昨晚,我快速尝试在我的 GXT 应用程序中实现用户名/密码自动完成。 我所说的“自动完成”并不是指 Ajax 风格的自动完成,而是基于浏览器的自动完成。 我通过谷歌找到的最佳信息在以下帖子中:

http:// /osdir.com/ml/GoogleWebToolkit/2009-04/msg01838.html

我没有使用此技术,因为我使用的是 GXT 并且不想丢失登录表单的外观。

我成功地让一切在 Firefox 中正常工作(它填充了用户名和密码)。 在 IE 中,它仅填充用户名,而不填充密码。 在 Safari/Chrome 中,它根本不起作用。

我是这样做的:

  • 在嵌入 GWT 的 HTML 页面上创建一个隐藏的 HTML 表单。
<form method="post" action="javascript:void(0)" style="display: none">
    <input type="text" id="username" name="username" value=""/>
    <input type="password" id="password" name="password" value=""/>
    <input type="submit" value="Login" id="login"/>
</form>
  • 当用户单击我的 GWT 应用程序中的“登录”按钮时,填充此隐藏表单中的字段并“单击”登录按钮(自 action="javascript:void(0)" 以来,这不会执行任何操作。
// Set the hidden fields to trigger the browser to remember
DOM.getElementById("username").setAttribute("value", username.getValue());
DOM.getElementById("password").setAttribute("value", password.getValue());
clickFormLogin();

...

public static native void clickFormLogin() /*-{
$doc.getElementById("login").click();
}-*/;

这有效在 Firefox 3.5 中,并提示我在屏幕顶部保存用户/密码,我相信我知道为什么这在 Safari/Chrome 中不起作用,那是因为表单的操作不会到达任何地方并且表单不会提交。如果我将操作更改为实际 URL 并显示表单,则单击表单的登录按钮会将其保存在这些浏览器中。

在此处将其作为问题输入后,我开始认为这可能是一篇很好的博客文章。 因此,我复制了所有内容并在我的博客中添加了一些内容:

http://raibledesigns.com/rd/entry/browser_based_username_password_autocomplete

摘要和问题< /strong>
虽然我很高兴它能在 Firefox 中运行,但我对 IE 缺乏密码自动完成功能感到失望。 最重要的是,我不禁想到有一种方法可以在基于 WebKit 的浏览器中实现这一点。

有人知道如何在 GWT (特别是 GXT)中实现跨浏览器用户名/密码自动完成吗?

Last night, I did a quick spike to try and implement username/password autocomplete in my GXT application. By "autocomplete", I don't mean Ajax-style autocomplete, but rather browser-based autocomplete. The best information I found on this via google is in the following post:

http://osdir.com/ml/GoogleWebToolkit/2009-04/msg01838.html

I didn't use this technique because I'm using GXT and didn't want to lose the look-and-feel of my login form.

I was successful in getting everything to work in Firefox (it populates both the username and password). In IE, it only populates the username, not the password. In Safari/Chrome, it doesn't work at all.

Here's how I did it:

  • Created a hidden HTML form on my HTML page that embeds GWT.
<form method="post" action="javascript:void(0)" style="display: none">
    <input type="text" id="username" name="username" value=""/>
    <input type="password" id="password" name="password" value=""/>
    <input type="submit" value="Login" id="login"/>
</form>
  • When a user clicks on the "Login" button in my GWT application, populate the fields in this hidden form and "click" on the Login button (which will do nothing since the action="javascript:void(0)".
// Set the hidden fields to trigger the browser to remember
DOM.getElementById("username").setAttribute("value", username.getValue());
DOM.getElementById("password").setAttribute("value", password.getValue());
clickFormLogin();

...

public static native void clickFormLogin() /*-{
$doc.getElementById("login").click();
}-*/;

This works in Firefox 3.5 and prompts me to save the user/pass at the top of the screen. I believe I know why this doesn't work in Safari/Chrome and that's because the form's action doesn't go anywhere and the form is not submitted. If I change the action to be an actual URL and show the form, clicking on the form's Login button will save it in those browsers.

After typing this up as a question here, I got to thinking this might make a good blog post. Therefore, I copied everything and added a bit to my blog:

http://raibledesigns.com/rd/entry/browser_based_username_password_autocomplete

Summary and Question
While I'm glad I got it working in Firefox, I'm disappointed with IE's lack of password autocompletion. More than anything, I can't help but think there's a way to make this work in WebKit-based browsers.

Anyone know how to implement cross-browser username/password autocomplete in GWT (specifically GXT)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落在眉间の轻吻 2024-08-08 19:55:39
  1. 请改用持久性 Cookie。
  2. 如果用户选择,IE 确实会保存密码,但其工作方式有所不同。 您至少需要输入用户名,以便它自动完成密码。
  1. Use persistent Cookies instead.
  2. IE do save passwords, if user chooses to, but it works different. You need to type at least the username so it will autocomplete the password.
绝不放开 2024-08-08 19:55:39

您需要一个普通的 html 提交按钮。 我认为这会解决它。

http://groups.google.com/group/Google- Web-Toolkit/browse_thread/thread/2b2ce0b6aaa82461

You need a plain vanilla html submit button. I think that will fix it.

http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/2b2ce0b6aaa82461

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文