禁用Firefox的自动填充 [英] Disable Firefox's Auto-fill

查看:113
本文介绍了禁用Firefox的自动填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以禁用Firefox的自动填充功能而不禁用自动填写功能?

我知道我可以这样做: p>

  autocomplete =off

但是我不想禁用auto-complete,只是自动填充。

Firefox正在填充一些隐藏字段这意味着是空的



当用户刷新页面时,这主要是一个问题。表单字段用预刷新的值重新填充。这是一个问题的例子是老派的地方。我们在哪里填充一个值,并在提交时删除它。这个值在刷新时重新填充,我们不知道它是否为占位符或使用值。

解决方案

如果问题是FF在用户刷新时填充字段,这实际上是Firefox的一个功能,在意外刷新的情况下尝试帮助用户,所以他们不会丢失任何输入的内容。我不认为你可以用HTML覆盖这个。您可以使用JavaScript清除/重置页面加载时的所有相关表单值。如果表单上的form.reset()不起作用,则必须遍历表单元素,并像下面这样清除它们:

 <$ (i = 0; i  {
field_type = frm_elements [i] .type.toLowerCase();
switch(field_type)
{
casetext:
casepassword:
casetextarea:
casehidden:
frm_elements [i] .value =;
break;
caseradio:
casecheckbox:
if(frm_elements [i] .checked)
{
frm_elements [i] .checked = false;
}
break;
caseselect-one:
caseselect-multi:
frm_elements [i] .selectedIndex = -1;
break;
默认值:
break;
}
}


Is it possible to disable Firefox's auto-fill feature without disabling auto-complete?

I know I can do this:

autocomplete="off"

But I don't want to disable auto-complete, just the auto-fill.

Firefox is populating some of our hidden fields which are meant to be empty

This is mostly a problem when the user refreshes the page. The form fields are re-populated with values from pre-refresh. An example of this being a problem is old-school place-holder. Where we populate the field with a value, and remove it on submit. The value is re-populated on refresh and we don't know if it's the place-holder or use value.

解决方案

If the problem is that FF is populating the fields when the user refreshes, this is actually a feature of Firefox to try to help the user in the case of accidental refresh so they don't lose whatever they have typed. I don't think you can override this with the HTML. You could use JavaScript to clear/reset all the relevant form values on page load. If a form.reset() on the form doesn't work, you will have to iterate over the form elements and clear them like this:

for (i = 0; i < frm_elements.length; i++)
{
    field_type = frm_elements[i].type.toLowerCase();
    switch (field_type)
    {
    case "text":
    case "password":
    case "textarea":
    case "hidden":
        frm_elements[i].value = "";
        break;
    case "radio":
    case "checkbox":
        if (frm_elements[i].checked)
        {
            frm_elements[i].checked = false;
        }
        break;
    case "select-one":
    case "select-multi":
        frm_elements[i].selectedIndex = -1;
        break;
    default:
        break;
    }
}

这篇关于禁用Firefox的自动填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆