国产探花免费观看_亚洲丰满少妇自慰呻吟_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"/>

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

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂温| 行唐县| 抚顺市| 邢台市| 台安县| 江永县| 安溪县| 榆中县| 双辽市| 吉首市| 时尚| 平山县| 壤塘县| 沿河| 山西省| 成都市| 屏东县| 潼南县| 海口市| 响水县| 横山县| 金山区| 轮台县| 平陆县| 安多县| 阿拉善右旗| 大洼县| 东海县| 庆云县| 惠水县| 泾川县| 芒康县| 博湖县| 雷波县| 茌平县| 大竹县| 开原市| 太仓市| 齐齐哈尔市| 新源县| 罗城|