亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

 更新時間:2017年04月28日 10:26:53   作者:minsong  
本篇文章主要介紹了解決瀏覽器會自動填充密碼問題的方法。具有很好的參考價值。下面跟著小編一起來看下吧

解決辦法是在form上或input上添加autoComplete="off"這個屬性。

form表單的屬性如下所示:

但是這個解決方案在谷歌和火狐上均有bug,下面來一個一個解決。

1.'autocomplete="off"'在Chrome中不起作用解決方案

網(wǎng)站項目中,有登錄和注冊的彈框,在除chrome的瀏覽器中一切都ok,一旦在谷歌瀏覽器中,問題來了:

首先從登錄彈框中登陸成功,chrome會彈出是否保存密碼的提示框,點擊保存密碼按鈕,

然后接著退出賬戶,

這時打開注冊彈框,你會發(fā)現(xiàn)注冊彈框中用戶名和密碼也被默認填寫進去了(登錄彈框中默認填寫進去符合邏輯),

這現(xiàn)象就詭異了,開始各種查,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瀏覽器則自動填充了用戶名和密碼的輸入框;為了統(tǒng)一樣式,我們需要就對Chrome的問題經(jīng)行單獨處理。

總結(jié)了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框中設(shè)置 autocomplete="new-password"

網(wǎng)上咱沒有找到對其詳細解釋,但是發(fā)現(xiàn)163郵箱的登錄注冊是這么用的,

所以就借鑒借鑒咯,測試之后也是可以解決問題的,也是最簡單的解決辦法,網(wǎng)易給您點個贊!

4 修改readonly屬性

<input type="password" readonly onfocus="this.removeAttribute('readonly');"/> 

但Firefox中有個Bug。首次提交后,F(xiàn)F會提示是否記住某某網(wǎng)站的密碼,點擊“記住”后 input[type=text]設(shè)置autocomplete="off"將不起作用。

有兩種情況:

1,form中沒有input[type=password],autocomplete="off"將起作用

2,去掉form,設(shè)置input[type=text]的autocomplete也起作用(測試不好用)

3.Firefox則需要使用另一個擴展屬性disableautocomplete  (測試也不行)

<input type="text"  disableautocomplete autocomplete="off"  id="number"/>

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

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!

相關(guān)文章

最新評論