NOTE: This question was heavily edited from its original version. The issue has been greatly simplified.
Similar questions have been asked several times before, in different forms - e.g.,
How can I get browser to prompt to save password?
How does browser know when to prompt user to save password?
However, this question is getting at a very specific aspect of Chrome's functionality, so it is quite different in that regard.
Judging by past answers, it appears that the best approach to getting Chrome to prompt for password saving is to submit the form to a dummy iframe, while actually logging in through AJAX: example. That makes sense to me and so I have been fiddling around with some sample code for a few days now. However, Chrome's behaviour in this regard DOES NOT make sense to me. At all. Hence the question.
For some reason, Chrome will not prompt you to save your password if the form that submits to a dummy iframe is present during/right after onDomReady.
A jsfiddle can be found here, but it's of little use because you must create dummy.html
locally to see the behaviour described. So the best way to see this is to copy the full html into your own index.html
and then create a dummy.html
file too.
Here is the full code for index.html
. The three approaches are highlighted as (1)
, (2)
, (3)
. Only (2)
ensures that the user is prompted to save their password, and the fact that (3)
doesn't work is particular perplexing to me.
<html>
<head>
<title>Chrome: Remember Password</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script type="text/javascript">
$(function(){
function create_login_form()
{
$('#login_form').html(
"<input type='text' name='email'>" +
"<input type='password' name='password'>" +
"<input id='login-button' type='submit' value='Login'/>");
}
// (1) this does not work. chrome seems to require time after "onDomReady" to process
// the forms that are present on the page. if the form fields exist while that processing
// is going on, they will not generate the "Save Password?" prompt.
//create_login_form();
// (2) This works. chrome has obviously finished its "work" on the form fields by now so
// we can add our content to the form and, upon submit, it will prompt "Save Password?"
setTimeout(create_login_form,500);
});
</script>
</head>
<body>
<!-- Our dummy iframe where the form submits to -->
<iframe src="dummy.html" name="dummy" style="display: none"></iframe>
<form action="" method="post" target="dummy" id="login_form">
<!-- (3) fails. form content cannot be present on pageload -->
<!--
<input type='text' name='email'>
<input type='password' name='password'>
<input id='login-button' type='submit' value='Login'/>
-->
</form>
</body>
</html>
If anyone could possibly explain what's going on here, I would be most appreciative.
EDIT: Note that this "saving password issue" with Chrome has extended to people working with AngularJS, also developed by Google: Github