最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Detecting browser autofill before selection - Stack Overflow

programmeradmin0浏览0评论

Is there anyway I can detect the autofill BEFORE the user selects an option from the dropdown?

Expected: 400010 as seen.

Currently I have:

$('input').on('input paste change keyup', function(event) {
    if(event.type=='input'){
      console.log( $(this).val() ); 
    }
});

.. and it works AFTER the user has made a selection, but not before as seen in the above screenshot.

Is there anyway I can detect the autofill BEFORE the user selects an option from the dropdown?

Expected: 400010 as seen.

Currently I have:

$('input').on('input paste change keyup', function(event) {
    if(event.type=='input'){
      console.log( $(this).val() ); 
    }
});

.. and it works AFTER the user has made a selection, but not before as seen in the above screenshot.

Share Improve this question asked Dec 19, 2014 at 6:23 eozzyeozzy 68.8k109 gold badges284 silver badges447 bronze badges 8
  • Possible duplicate ? : stackoverflow./questions/11708092/detecting-browser-autofill – DarkHorse Commented Dec 19, 2014 at 6:28
  • @DarkHorse No, tried that, none of those solutions work. – eozzy Commented Dec 19, 2014 at 6:29
  • Just to clarify, change is detected AFTER the selection is made and the field is still in focus, but I need text changes DURING the selection when the user hovers over the options. – eozzy Commented Dec 19, 2014 at 6:30
  • 4 you don't have access to users stored autofill data for fairly obvious security reasons – charlietfl Commented Dec 19, 2014 at 6:37
  • 3 Unfortunately, this is not possible.... :( Here is a report on the issue where they say We do send a change event when a user chooses to autofill. I think the "bug" you're observing is that username/pw fields aren't really autofilled until the user interacts with the page (for security/privacy reasons). Hope this helps. – Dom Commented Jan 21, 2015 at 6:04
 |  Show 3 more ments

2 Answers 2

Reset to default 6 +50

Read this article, they go in-depth on detected auto-fill events. The problem is that not all browsers support auto-fill events, however I don't think any would be foolish enough to support this feature before the user makes a selection. Think about this: if they supported auto-fill events before a selection was made it would be extremely simple to steal peoples passwords, zipcodes, credit cards, etc. Since you could just send an AJAX request containing the auto pleted information in each of these fields, regardless of whether the user actually selected them.

Sorry, if I couldn't be of more help.

try like this:

$(document).ready(
function (event) {
    $('.ddClass').on('mouseenter', 'option', function(e) {
    $("#zipcode").val(this.value);

);
});

//where .ddClass is the class of dropdown option

发布评论

评论列表(0)

  1. 暂无评论