为什么不这种形式提示浏览器提供保存密码? [英] Why won't this form prompt the browser to offer to save password?

查看:154
本文介绍了为什么不这种形式提示浏览器提供保存密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下形式放置在页面上通过AJAX(jQuery的AJAX是否有帮助):

I have the following form which is placed on the page through AJAX (jQuery AJAX if that helps):

        <div id="login">
            <iframe src="/api/core/authSystem/authUser.php" id="temp" name="temp" style="display:none"></iframe>
            <form id="loginForm" target="temp" onSubmit="App.Auth.login(); return false;">
                Email: <input type="text" name="email" id="email" onkeydown='if(event.keyCode == 13){ this.submit; }' /><br />
                Password: <input type="password" name="password" id="password" onkeydown='if(event.keyCode == 13){ this.submit; }' /><br />
                <div class="errorMsg" id="loginError"></div>
                <div class="loginHelp l"><a href="#">Cant access your account?</a></div>
                <input class="button rounded r" type="submit" id="loginButton" value="Log In" />
            </form>
        </div>

继<一提出的建议href="http://stackoverflow.com/questions/2382329/how-can-i-get-browser-to-prompt-to-save-password">This问我加了iframe和我瞄准这一点。然而,浏览器仍然不会提示用户保存密码。知道为什么吗?

Following the suggestions made in This Question I added the iframe and am targeting that. However, browsers still will not prompt users to save the password. Any idea why?

编辑:我刚才注意到,Firefox会询问保存密码,但不会真正把它变成了形式,一旦你返回到登录页面

I have just noticed that Firefox will ask to save the password, but will not actually place it into the form once you return to the login page.

推荐答案

您可以尝试双提交技术。

You can try "double-submit" technique.

总之:在第一次提交取消,但成功后的权威性再次触发它,不取消

In short: on first submit cancel it, but trigger it again after successful auth and do not cancel it.

更详细的:

您需要重写你的表单是这样的:

You need to rewrite your form like this:

&LT;形式ID =登录表单的onsubmit =返回App.Auth.login();方法=POSTACTION =/背重定向&GT;

/背重定向只是重定向回到同一页面或主页。我重定向回到同一页。

/back-redirector just redirects back to the same page or to the main page. I am redirecting back to the same page.

和您的 App.Auth.login()函数必须返回false 当它被称为第一次和返回true 如果第一次调用导致成功登录。

And your App.Auth.login() function must return false when it is called first time, and return true if the first call has resulted in successful login.

这样的:

letTheLoginFormDoTheSubmit = false; 
// flag to show that login was successful 
// and we need to trigger password save prompt.

login: function() {
    if (letTheLoginFormDoTheSubmit) {
        return true;
    }
    // Do the login
    // Start ajax
    ajax(login, password, function() {
        // This function is called when AJAX has completed
        if (loginIsGood) {
            letTheLoginFormDoTheSubmit = true;
            loginForm.submit(); // trigger submit again
        });
    return false;
}

所以会发生什么?

So what happens?

  1. 当您的登录功能被称为第一次启动登录序列,并返回false阻止通常的形式提交。
  2. 在登录功能接收数据时,如果登录是很好的将其保存在浏览器端,提高了标志都好,触发密码保存提示,并再次提交表单。
  3. 但由于飘扬登录功能不会再次进行登录,它只是让浏览器做的通常形式提交,而这将触发密码保存提示。

窗体被提交到只是重定向浏览器回URL,并没有做任何的工作。

Form is being submitted to the URL that just redirects browser back, and does not do any work.

一些注意事项:

  • 在页面将重新加载,这样可节省您的身份验证cookie中莫名其妙地在本地,还是让重定向知道哪个是它,所以重定向可以将其包含在一个重定向。
  • 在所有形式的数据可能会经历第二次提交。为了避免,形式是删除相关的领域,或删除的name属性。
  • 在重定向器需要在服务器端。

但总体来说不是一个主要的变化在登录过程中,应当触发密码保存提示在每个浏览器。

But in overall it is not a major change to the login process and should trigger password-save prompt in every browser.

这篇关于为什么不这种形式提示浏览器提供保存密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆