Stop LastPass filling out a form

前端 未结 13 1720
遇见更好的自我
遇见更好的自我 2020-12-07 13:38

Is there a way to prevent the LastPass browser extension from filling out a HTML-based form with a input field with the name \"username\"?

This is an hidden field,

13条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-07 14:08

    None of the options here (autocomplete, data-lpignore etc.) prevented LastPass from auto-filling my form fields unfortunately. I took a more sledge-hammer approach to the problem and asynchronously set the input name attributes via JavaScript instead. The following jQuery-dependent function (invoked from the form's onsubmit event handler) did the trick:

    function setInputNames() {
        $('#myForm input').each(function(idx, el) {
            el = $(el);
            if (el.attr('tmp-name')) {
                el.attr('name', el.attr('tmp-name'));
            }
        });
    }
    
    $('#myForm').submit(setInputNames);
    

    In the form, I simply used tmp-name attributes in place of the equivalent name attributes. Example:

    Update 2019-03-20

    I still ran into difficulties with the above on account of AngularJS depending upon form fields having name attributes in order for ngMessages to correctly present field validation error messages.

    Ultimately, the only solution I could find to prevent LastPass filling password fields on my Password Change form was to:

    1. Avoid using input[type=password]entirely, AND
    2. to not have 'password' in the field name

    Since I need to be able to submit the form normally in my case, I still employed my original solution to update the field names 'just in time'. To avoid using password input fields, I found this solution worked very nicely.

提交回复
热议问题