By Deleting cookies
This method in which we can use to remove the password, also other values from the form. The values are stored in the browser in the form of a cookie, so if the cookies are deleted then the password, as well as other values, also deleted. So only we have to add a function to delete the cookies.
Example 1:In this example we will see how to prevent browser to remember password by deleting cookies.
html
< html > < head > < script type = "text/javascript" > function savePass() { passVal = "password = " + escape(document.Frm.passWord.value) + ";"; document.cookie = passVal + "expires = Sun, 01-May-2021 14:00:00 GMT"; document.getElementById("show").innerHTML = "Password saved, " + document.cookie; } function dltPass() { document.cookie = passVal + "expires = Sun, 01-May-2019 14:00:00 GMT"; // Set the expiration date to // removes the saved password document.getElementById("show").innerHTML = "Password deleted!!!"; // Removes the password from the browser document.getElementById("pass").value = ""; // Removes the password from the input box } </ script > </ head > < body > < div > < h2 style = "color: #006400;" > Preventing Password remember </ h2 > < form name = "Frm" > User Name : < input id = "username" type = "text" name = "userName" /> < br />< br /> Password: < input id = "pass" type = "password" name = "passWord" /> < br />< br /> < input id = "uname" type = "button" value = "submit" onclick = "savePass();" /> < input id = "remove" type = "button" value = "Remove given Password" onclick = "dltPass();" /> < p id = "show" ></ p > </ form > </ div > </ body > </ html > |
Output:
How to prevent browser to remember password in HTML ?
Browsers remember information that is submitted through <input> fields on websites for the first time when we use that particular website in that browser. So another time when we again submit data on that website through that browser then there is a suggestion list of submitted values in that field. Many times this may create security issues for many cases. Some of the methods are as:
Table of Content
- Using autocomplete attribute
- By Deleting cookies
- Using autocomplete=”new-password”