Skip to content Skip to sidebar Skip to footer

How To Detect When Browser Places Saved Password?

I'm trying to detect when a browser places a saved username and password into the input fields. I've looked at this post , but I don't have the option to change this functionality,

Solution 1:

I think there is no way to detect if the browser has some buil-in feature that pre-populates the fields.

You could solve the problem with the a timer that enable the button, if something is there. Something like this:

setInterval(function (){
 if($("#username").val()!=""){
  $("#loginbutton").attr("enabled","enabled"); 
 }
},1000)

Solution 2:

The key thing is that the field will be populated without there having being any keypresses in the field.

So if you trap .keypress on the input field to know if a key is any pressed, then if you get to submitting the form and find there were no keypresses despite a value being there - then you can be somewhat sure that the browser pre-populated it.

If you want to know before submitting (soon after the page loads), you'd want to run a check on an interval that sees if the value has changed despite no key presses.

As @japrescott pointed out, you might want to check for .focus as well in case the user pastes a value in.

Solution 3:

Haven't test this, but couldn't you simply compare the default values of each field to the values of each field after the page is loaded (or .2 seconds after the page is loaded if that's an issue)?

Solution 4:

Give a shoot to Jquery .live() function

$('.element').live('load', function(){
  enableLogin();
});

Post a Comment for "How To Detect When Browser Places Saved Password?"