input type=password 浏览器会自动填充密码的问题
解决办法是在form上或input上添加autoComplete="off"这个属性。
form表单的属性如下所示:
但是这个解决方案在谷歌和火狐上均有bug,下面来一个一个解决。
1.'autocomplete="off"'在Chrome中不起作用解决方案
网站项目中,有登录和注册的弹框,在除chrome的浏览器中一切都ok,一旦在谷歌浏览器中,问题来了:
首先从登录弹框中登陆成功,chrome会弹出是否保存密码的提示框,点击保存密码按钮,
然后接着退出账户,
这时打开注册弹框,你会发现注册弹框中用户名和密码也被默认填写进去了(登录弹框中默认填写进去符合逻辑),
这现象就诡异了,开始各种查,cookie,本地缓存,等等,都解决不了这问题;
查阅后,很多没有这个的解决方案。
1 通常我们会在form表单上加入autocomplete="off" 或者 在输入框中加入autocomplete="off"
- <form method="post" action="" name="login" autocomplete="off">
- </form>
- //或者
- <input id="name" type="text" name="name" maxlength="20" autocomplete="off">
2 但是有一种情况例外,就是表单中有input[type="password"],点击保存密码后,在Chrome浏览器则自动填充了用户名和密码的输入框;为了统一样式,我们需要就对Chrome的问题经行单独处理。
总结了4种解决方案,如下:
1 修改disabled属性
- if(navigator.userAgent.toLowerCase().indexOf("chrome") != -1){
- var inputers = document.getElementsByTagName("input");
- for(var i=0;i<inputers.length;i++){
- if((inputers[i].type !== "submit") && (inputers[i].type !== "password")){
- inputers[i].disabled= true;
- }
- }
- setTimeout(function(){
- for(var i=0;i<inputers.length;i++){
- if(inputers[i].type !== "submit"){
- inputers[i].disabled= false;
- }
- }
- },100)
- }
2 去除输入框的name和id属性
- if(navigator.userAgent.toLowerCase().indexOf("chrome") != -1){
- var inputers = document.getElementsByTagName("input");
- for(var i=0;i<inputers.length;i++){
- if((inputers[i].type !== "submit") && (inputers[i].type !== "password")){
- var input = inputers[i];
- var inputName = inputers[i].name;
- var inputid = inputers[i].id;
- inputers[i].removeAttribute("name");
- inputers[i].removeAttribute("id");
- setTimeout(function(){
- input.setAttribute("name",inputName);
- input.setAttribute("id",inputid);
- },1)
- }
- }
- }
3.可以在不需要默认填写的input框中设置 autocomplete="new-password"
网上咱没有找到对其详细解释,但是发现163邮箱的登录注册是这么用的,
所以就借鉴借鉴咯,测试之后也是可以解决问题的,也是最简单的解决办法,网易给您点个赞!
4 修改readonly属性
<input type="password" readonly onfocus="this.removeAttribute('readonly');"/>
但Firefox中有个Bug。首次提交后,FF会提示是否记住某某网站的密码,点击“记住”后 input[type=text]设置autocomplete="off"将不起作用。
有两种情况:
1,form中没有input[type=password],autocomplete="off"将起作用
2,去掉form,设置input[type=text]的autocomplete也起作用(测试不好用)
3.Firefox则需要使用另一个扩展属性disableautocomplete (测试也不行)
<input type="text" disableautocomplete autocomplete="off" id="number"/>
来自:http://www.jb51.net/article/112452.htm
input type=password 浏览器会自动填充密码的问题的更多相关文章
- 游览器保存密码和自动填充密码的困惑 (browser save password and auto fill password )
原文 refer : http://www.cnblogs.com/happyfreelife/p/4240100.html 当一个带有username and password 的表单被提交, 游览 ...
- 解决谷歌浏览器给输入框input自动填充密码问题
这时候我们可能会在 input上 加上 autocompleted="off" 这个属性来阻止input被自动填充. <input type="text" ...
- 解决chrome浏览器自动填充密码
chrome会自动填充密码,解决方法很简单 使用下面的参考代码即可: <input type="password" readonly οnfοcus="this.r ...
- 解决chrome浏览器对于自动填充的input表单添加的默认的淡黄色背景问题 && 一般的浏览器input和button的高度不一致问题
解决chrome浏览器对于自动填充的input表单添加的默认的淡黄色背景问题 如果我们把一个表单设置位 autofocus ,这时这个表单在获取焦点后就会产生淡黄色的背景,我们就是使用!importa ...
- Chrome浏览器下自动填充的输入框背景
记录下从张鑫旭老师的微博中看到关于input输入框的属性 1.autocomplete="off" autocomplete 属性规定输入字段是否应该启用自动完成功能 自动完成允许 ...
- [转载]Js小技巧||给input type=“password”的输入框赋默认值
http://www.cnblogs.com/Raywang80s/archive/2012/12/06/2804459.html [转载]Js小技巧||给input type="passw ...
- chrome表单禁止自动填充密码
在用户登录成功以后,chrome会提示用户记住密码. 用户退出以后若前往注册.忘记密码页时会自动填充密码. 若不希望自动填充密码,只需在input里设置autoComplete="new-p ...
- BUG笔记:Win8 IE10下input[type="password"]内字符显示被截取问题
这个BUG发生的截图: 这是发生在Windows8 IE10下,type为password的input文本框内输入长串字符后,初次失去焦点的时候会发生的一个BUG. 发生BUG的原因是这个文本框上应用 ...
- chrome防止自动填充密码
是防止,不是禁止.禁止需要在浏览器设置. chrome浏览器保存密码之后,页面上有password存在的时候会出现自动填充用户名和密码的情况. 添加disableautocomplete和autoco ...
随机推荐
- configure: error: Cannot find php_pdo_driver.h.
安装pdo_mysql cd /usr/local/src/php-5.4.0/ext/pdo_mysql/ /usr/local/php/bin/phpize # /usr/local/php为 ...
- VMware Workstation 虚拟机设置连接U盘
首先确保主机有开启"VMware USB Arbitration Service"服务,而且在执行中. 如图:(我的系统是win8.1 ) 在VMware Workstation虚 ...
- fatal error C1189: #error : core.hpp header must be compiled as C++
两次opencv工程需要设置为C++编译:找了一半天的解决方法. I am building a C application that uses OpenCV. when compiling, I g ...
- 转:某运维DBA的mysql学习心得
转自:http://www.cnblogs.com/lyhabc/p/3691555.html 我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心 ...
- [WASM Rust] Create and Publish a NPM Package Containing Rust Generated WebAssembly using wasm-pack
wasm-pack is a tool that seeks to be a one-stop shop for building and working with Rust generated We ...
- linux字符设备驱动程序框架(老方法)
#include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #inclu ...
- ElasticDownload
https://github.com/eltld/ElasticDownload
- android-測试so动态库(九)
1.依照androidproject向导一步步新建一个 2.将jar包放在libs文件夹下 3.在libs文件夹下新建armeabi文件夹.以及将so动态库放在该文件夹下 4.引用动态库,代码測试 p ...
- 2016/05/27 php上传文件常见问题总结
php上传文件常见问题总结 投稿:hebedich 字体:[增加 减小] 类型:转载 时间:2015-02-03我要评论 这篇文章主要介绍了php上传文件常见问题总结,基本上经常碰到的问题的处理都列了 ...
- HDU 6073 Matching In Multiplication dfs遍历环 + 拓扑
Matching In Multiplication Problem DescriptionIn the mathematical discipline of graph theory, a bipa ...