2012-09-25 39 views
0

有什麼辦法,我們可以從客戶端腳本中檢測到自動完成的瀏覽器設置?不同的瀏覽器有不同的自動完成設置。從javascript中檢測瀏覽器自動完成設置

我想根據自動填充功能的客戶端瀏覽器設置將autocomplete =「off」添加到文本字段。

+1

我不確定,但我猜測訪問與瀏覽器中的自動完成功能相關的任何事情都是一個很大的安全風險,並且是一個不允許的。 – adeneo

+1

難道你不能只是禁用它 - 不支持它的瀏覽器將忽略它 – danwellman

+0

不幸的是,禁用該功能和包含這種文本字段的頁面的可用性之間存在折衷。有些用戶覺得很難填寫文本框。這就是爲什麼我想使它有條件.. – Karan

回答

1

你爲什麼不穀歌,我的朋友.....

http://help.dottoro.com/ljdwgiwh.php

Example Code: 

填寫用戶名和城市領域的一些文字內容,並提交表單。
之後,開始用相同的內容填充這些字段。自動完成窗口將顯示給用戶名字段。

<head> 
    <script type="text/javascript"> 
     function DisableAutoComp() { 
      var username = document.getElementById ("username"); 
      if ('autocomplete' in username) { 
       username.autocomplete = "off"; 
      } 
      else { 
        // Firefox 
       username.setAttribute ("autocomplete", "off"); 
      } 
     } 
    </script> 
</head> 
<body> 
    Fill the user name and city fields with some text content, and submit the form.<br /> 
    After that, start to fill these fields with the same content. An autocomplete window will displayed for to the user name field. 
    <br /><br /> 
    <form method="post" action="#URL#"> 
     User name, with autocompletion: 
     <input type="text" id="username" name="username" autocomplete="on" /> 
     <br /> 
     City, without autocompletion: 
     <input type="text" name="city" autocomplete="off" /> 

     <br /><br /> 
     <input type="submit" value="Send" /> 
    </form> 
    <br /> 
    <button onclick="DisableAutoComp();">Disable autocompletion!</button> 
</body>