Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 禁用表单密码自动完成,但不禁用其他字段_Javascript_Html_Spring_Autocomplete - Fatal编程技术网

Javascript 禁用表单密码自动完成,但不禁用其他字段

Javascript 禁用表单密码自动完成,但不禁用其他字段,javascript,html,spring,autocomplete,Javascript,Html,Spring,Autocomplete,我知道您可以通过在表单本身上设置autocomplete=“off”来禁用表单上的自动完成功能 我的问题是,我想阻止浏览器填充密码字段,但不想禁用用户名或其他字段 另一个需要考虑的是遗留数据。在表单(甚至字段本身)上使用autocomplete=“off”不会阻止已保存密码的现有用户获得免费通行证。或者使用web inspector的用户,更改autocomplete和submit的值,允许自己保存密码 我知道每次访问时都可以将密码字段name属性更改为随机/新的。遗憾的是,我正在使用java/

我知道您可以通过在表单本身上设置
autocomplete=“off”
来禁用表单上的自动完成功能

我的问题是,我想阻止浏览器填充密码字段,但不想禁用用户名或其他字段

另一个需要考虑的是遗留数据。在表单(甚至字段本身)上使用
autocomplete=“off”
不会阻止已保存密码的现有用户获得免费通行证。或者使用web inspector的用户,更改autocomplete和submit的值,允许自己保存密码

我知道每次访问时都可以将密码字段
name
属性更改为随机/新的。遗憾的是,我正在使用java/spring后端,有人告诉我,如果没有一个巨大的重构/覆盖,这是不容易管理的

你将如何设计这个?您将如何强制该字段始终以空开头?浏览器没有一致的方式通过密码管理器通知您预填充事件-有些可能会触发onChange,有些可能不会


我想我可以用javascript移动字段,动态构建真正的表单并提交它,但这同样会对spring安全性和验证等产生影响。还有其他想法吗?

当调用onFocus时,可以创建一个临时变量,将变量设置为true(如userFocus) 在onChange attribute上,如果userFocus==false,将“value”重置为NULL的一段短代码)有点过分,但可能会起作用

编辑

function reset()
{
if (document.getElementById("hidden").value!=" ")
{
document.getElementById("demo").value=" ";
}
else;
}

function getfocus()
{
document.getElementById("hidden").value=" ";
}
else;
}

<input type="password" id="pwd" onchange="reset()" onfocus="getfocus()"/>
<input type="hidden" id="hidden" value="not focus"/>
函数重置()
{
if(document.getElementById(“隐藏”).value!=“”)
{
document.getElementById(“demo”).value=“”;
}
其他的
}
函数getfocus()
{
document.getElementById(“隐藏”).value=“”;
}
其他的
}

当调用onFocus将变量设置为true(如userFocus)时,可以创建一个临时变量 在onChange attribute上,如果userFocus==false,将“value”重置为NULL的一段短代码)有点过分,但可能会起作用

编辑

function reset()
{
if (document.getElementById("hidden").value!=" ")
{
document.getElementById("demo").value=" ";
}
else;
}

function getfocus()
{
document.getElementById("hidden").value=" ";
}
else;
}

<input type="password" id="pwd" onchange="reset()" onfocus="getfocus()"/>
<input type="hidden" id="hidden" value="not focus"/>
函数重置()
{
if(document.getElementById(“隐藏”).value!=“”)
{
document.getElementById(“demo”).value=“”;
}
其他的
}
函数getfocus()
{
document.getElementById(“隐藏”).value=“”;
}
其他的
}

我必须为IE 11找到这个解决方案(因为它忽略了autocomplete属性)。它可以在其他浏览器中正常工作。实际上,这更像是一项工作,但它是有效的。
我必须为IE 11找到这个解决方案(因为它忽略了自动完成属性)。它可以在其他浏览器中正常工作。实际上,这更像是一项工作,但它是有效的。

我最近遇到了这个问题,由于我的字段可以预填充,因此没有简单的解决方案,我想与大家分享一个通过在ready事件中设置密码类型而获得的优雅技巧

创建输入字段时不要将其声明为类型密码,而是添加一个就绪事件侦听器来为您添加它:

function createSecretTextInput(name,parent){
    var createInput = document.createElement("input");
    createInput.setAttribute('name', name);
    createInput.setAttribute('class', 'secretText');
    createInput.setAttribute('id', name+'SecretText');
    createInput.setAttribute('value', 'test1234');

    if(parent==null)
       document.body.appendChild(createInput);
    else
        document.getElementById(parent).appendChild(createInput);

    $(function(){
        document.getElementById(name+'SecretText').setAttribute('type', 'password');
    });
};

createSecretTextInput('name', null);

我最近遇到了这个问题,由于我的字段可以预填充,因此没有简单的解决方案,我想与大家分享一个通过在ready事件中设置密码类型而获得的优雅技巧

创建输入字段时不要将其声明为类型密码,而是添加一个就绪事件侦听器来为您添加它:

function createSecretTextInput(name,parent){
    var createInput = document.createElement("input");
    createInput.setAttribute('name', name);
    createInput.setAttribute('class', 'secretText');
    createInput.setAttribute('id', name+'SecretText');
    createInput.setAttribute('value', 'test1234');

    if(parent==null)
       document.body.appendChild(createInput);
    else
        document.getElementById(parent).appendChild(createInput);

    $(function(){
        document.getElementById(name+'SecretText').setAttribute('type', 'password');
    });
};

createSecretTextInput('name', null);

我唯一能想到的是在dom就绪后插入密码输入框…你可能无法100%阻止它,请看-但你的脚本想法也是我能想到的最佳解决方案。顺便说一句,我的银行网上银行使用基于Flash的登录表单。他们说这是为了安全。也许他们的想法和你一样。我唯一能想到的就是在dom就绪后插入密码输入框…你可能无法100%阻止它,看到了吗?但是你的脚本想法也是我能想到的最好的解决方案。顺便说一句,我的银行网上银行使用基于Flash的登录表单。他们说这是为了安全。也许他们的想法和你一样。