欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

解決瀏覽器會(huì)自動(dòng)填充密碼的問題

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

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

form表單的屬性如下所示:

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

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

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

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

然后接著退出賬戶,

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

這現(xiàn)象就詭異了,開始各種查,cookie,本地緩存,等等,都解決不了這問題;

查閱后,很多沒有這個(gè)的解決方案。

1  通常我們會(huì)在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"],點(diǎn)擊保存密碼后,在Chrome瀏覽器則自動(dòng)填充了用戶名和密碼的輸入框;為了統(tǒng)一樣式,我們需要就對(duì)Chrome的問題經(jīng)行單獨(dú)處理。

總結(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.可以在不需要默認(rèn)填寫的input框中設(shè)置 autocomplete="new-password"

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

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

4 修改readonly屬性

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

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

有兩種情況:

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

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

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

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

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

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

相關(guān)文章

最新評(píng)論