Firefox keeps form data on reload

2019-01-10 20:29发布

I have a big problem with the functionality in Firefox that keeps data that the user have filled in on reload F5. If i use Ctrl+F5 the forms are cleared and this is great. My problem is that not all my users know that this is what they have to do to force the input cleanup. Is there a way in the html or response headers to tell Firefox to not keep the data in the forms?

7条回答
女痞
2楼-- · 2019-01-10 20:32

Instead of going through all inputs you may also just add the attribute to your form-element like so:

<form method="post" autocomplete="off">...</form>

However the above mentioned methods on domReady did not work for me...

查看更多
女痞
3楼-- · 2019-01-10 20:35

I think easier and quicker way to do that is

$('input,textarea').attr('autocomplete', 'off');
查看更多
劳资没心,怎么记你
4楼-- · 2019-01-10 20:43

Just add autocomplete="off" to all you input and you will solve the problem.

<input type="text" autocomplete="off">

jQuery to solve this on all inputs and textareas

$('input,textarea').attr('autocomplete', 'off');
查看更多
别忘想泡老子
5楼-- · 2019-01-10 20:46

I found the only fix for me was to do

document.forms[0].reset();

before doc ready early in the page, as suggested in the comment by @Marek above - not great but worked for me (the autocomplete attribute method via either jQuery, JS or HTML didn't in the end fix it for me)

查看更多
冷血范
6楼-- · 2019-01-10 20:51

I tried the shortened solution above, but it didn't clear the value of the select boxes on my page.

I ended up modifying it slightly and now all input types on the page are cleared regardless of type:

var allInputs = $(":input");
$(allInputs).attr('autocomplete', 'off');

So to make this run onload I just put it in the ready() method:

$(document).ready(function () {
    var allInputs = $(":input");
    $(allInputs).attr('autocomplete', 'off');
});
查看更多
男人必须洒脱
7楼-- · 2019-01-10 20:52
/*reset form elements (firefox saves it)*/

function resetElements()
{
     var inputs = document.querySelectorAll('input[type=text]');
     //you get the idea.....you can retrieve all inputs by tag name input
     for(var i = 0; i < inputs.length; i++) {
         document.getElementsByTagName('input')[i].value = "";
     }
     var textareas = document.getElementsByTagName('textarea');
     for(var i = 0; i < textareas.length; i++) {
         document.getElementsByTagName('textarea')[i].value = "";
     }
}

Call this function onload.

查看更多
登录 后发表回答