I have an application running with Backbone.js
, and I need to trigger the browser password save when logging in.
Currently I am using preventDefault
when the form is submitted, and thus the password save is not triggered. When searching for this I find old posts about using iFrames and stuff, which seems obsolete, so my question is:
How do you trigger the password save prompt, when handling form submit in JS?
I don't think you can force the Browser to do that; What I'm sure you can do is, after the ajax (or anything) post request, do a form submit something like that
in jquery :
$.ajax({
url:requestUrl,
success: function (data, text) {
//Request Finished with Success
$('#Form').submit();
},
error: function (request, status, error) {
//Request Finished with Error
}
});
in VanillaJS :
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if(request.readyState === 4) {
//Request Finished
if(request.status === 200) {
//Success
document.getElementById('Form').submit();
} else {
//Error
}
}
}
request.open('POST', URL);
request.send();
This way you let the Browser and the User keep control over what happens. If you still want to save the password then use cookies, Here is something you might use
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.