How can I get browser to prompt to save password?

前端 未结 20 1534
面向向阳花
面向向阳花 2020-11-22 16:20

Hey, I\'m working on a web app that has a login dialog that works like this:

  1. User clicks \"login\"
  2. Login form HTML is loaded with AJAX and displayed i
20条回答
  •  礼貌的吻别
    2020-11-22 16:49

    Using a button to login:

    If you use a type="button" with an onclick handler to login using ajax, then the browser won't offer to save the password.

    Since this form does not have a submit button and has no action field, the browser will not offer to save the password.


    Using a submit button to login:

    However, if you change the button to type="submit" and handle the submit, then the browser will offer to save the password.

    Using this method, the browser should offer to save the password.


    Here's the Javascript used in both methods:

    function login(f){
        var username = f.username.value;
        var password = f.password.value;
    
        /* Make your validation and ajax magic here. */
    
        return false; //or the form will post your data to login.php
    }
    

提交回复
热议问题