Firefox caches hidden inputs

I have a hidden input field in my form. I noticed that if that field’s value is changed by javascript, and then the user refreshes the page, that same value will be set when the page reloads. From what I’ve seen, this only happens in Firefox.

I’ve solved this unwanted behaviour by adding autocomplete="off" to that hidden input, but W3Cdoesn’t like this solution, and if i validate the page I get the error:

Attribute autocomplete not allowed on element input at this point.

Apparently, the autocomplete attribute works only on specific inputs – see here.

So is there any solution that will satisfy both W3C and Firefox?

To validate (which I wouldn’t put as much effort into as you are) I think you could use autocomplete="off" on the entire form, then turn it back on selectively, like this:

<!DOCTYPE html>
    <form autocomplete="off">
        <input type="hidden" name="test">
        <input type="text" name="otherfield" autocomplete="on">

I initially thought this was a Firefox bug but after discussion with robertc in the comments, I think expected behavior depends on specific use cases. The spec doesn’t allow autocompletion on hidden fields so my first reaction still feels right, but Firefox’s implementation might have some good arguments to support it. Please comment.


电子邮件地址不会被公开。 必填项已用*标注