国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

解決瀏覽器會自動填充密碼的問題

2019-11-19 16:42:11
字體:
來源:轉載
供稿:網友

解決辦法是在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"/>

火狐現在也沒有解決的辦法,,誰有麻煩告知一下哈。。。。。

以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持武林網!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 余江县| 牟定县| 星子县| 元江| 平顶山市| 四子王旗| 开封市| 出国| 三河市| 胶南市| 尤溪县| 济阳县| 安阳市| 丹阳市| 淄博市| 台中市| 娄底市| 河北区| 都昌县| 嘉黎县| 江都市| 梓潼县| 板桥市| 文安县| 辛集市| 集安市| 正蓝旗| 拉萨市| 盈江县| 巨野县| 松阳县| 武强县| 会宁县| 北宁市| 加查县| 怀宁县| 肇州县| 泸溪县| 辉县市| 饶阳县| 珲春市|