从javascript中检测浏览器自动完成设置
是否有任何方法可以从客户端脚本检测autocomplete的浏览器设置?不同的浏览器具有不同的自动完成设置从javascript中检测浏览器自动完成设置,javascript,jquery,Javascript,Jquery,是否有任何方法可以从客户端脚本检测autocomplete的浏览器设置?不同的浏览器具有不同的自动完成设置 我想根据“自动完成”功能的客户端浏览器设置将“自动完成”=“关闭”添加到文本字段。为什么不用谷歌搜索它呢,我的朋友 在用户名和城市字段中填入一些文本内容,然后提交表单。 之后,开始用相同的内容填充这些字段。将为用户名字段显示自动完成窗口 <head> <script type="text/javascript"> function Di
我想根据“自动完成”功能的客户端浏览器设置将“自动完成”=“关闭”添加到文本字段。为什么不用谷歌搜索它呢,我的朋友 在用户名和城市字段中填入一些文本内容,然后提交表单。
之后,开始用相同的内容填充这些字段。将为用户名字段显示自动完成窗口
<head>
<script type="text/javascript">
function DisableAutoComp () {
var username = document.getElementById ("username");
if ('autocomplete' in username) {
username.autocomplete = "off";
}
else {
// Firefox
username.setAttribute ("autocomplete", "off");
}
}
</script>
</head>
<body>
Fill the user name and city fields with some text content, and submit the form.<br />
After that, start to fill these fields with the same content. An autocomplete window will displayed for to the user name field.
<br /><br />
<form method="post" action="#URL#">
User name, with autocompletion:
<input type="text" id="username" name="username" autocomplete="on" />
<br />
City, without autocompletion:
<input type="text" name="city" autocomplete="off" />
<br /><br />
<input type="submit" value="Send" />
</form>
<br />
<button onclick="DisableAutoComp ();">Disable autocompletion!</button>
</body>
函数DisableAutoComp(){
var username=document.getElementById(“用户名”);
如果(用户名中的“自动完成”){
username.autocomplete=“关闭”;
}
否则{
//火狐
username.setAttribute(“自动完成”、“关闭”);
}
}
在用户名和城市字段中填入一些文本内容,然后提交表单。
之后,开始用相同的内容填充这些字段。将为用户名字段显示自动完成窗口。
用户名,带自动完成:
城市,无自动完成:
禁用自动完成!
我不确定,但我猜访问浏览器中与自动完成功能相关的任何内容都是一个巨大的安全风险,不可以。你不能禁用它吗?不支持它的浏览器将忽略iTunes。在禁用该功能和包含此类文本字段的页面的可用性之间存在着权衡。一些用户觉得重新填充文本字段很烦人。这就是为什么我想让它成为有条件的。@Karan你还没有解释为什么要禁用它?如果出于安全原因,那么用户满意度可以忽略,您可以完全禁用它。
<head>
<script type="text/javascript">
function DisableAutoComp () {
var username = document.getElementById ("username");
if ('autocomplete' in username) {
username.autocomplete = "off";
}
else {
// Firefox
username.setAttribute ("autocomplete", "off");
}
}
</script>
</head>
<body>
Fill the user name and city fields with some text content, and submit the form.<br />
After that, start to fill these fields with the same content. An autocomplete window will displayed for to the user name field.
<br /><br />
<form method="post" action="#URL#">
User name, with autocompletion:
<input type="text" id="username" name="username" autocomplete="on" />
<br />
City, without autocompletion:
<input type="text" name="city" autocomplete="off" />
<br /><br />
<input type="submit" value="Send" />
</form>
<br />
<button onclick="DisableAutoComp ();">Disable autocompletion!</button>
</body>