The password
property sets or gets the
password part of the href attribute value.
Example: https://userName:password@www.example.com.
password |
Yes | No | Yes | No | Yes |
Return the password property:
var v = anchorObject.password
Set the password property:
anchorObject.password = password;
Value | Description |
---|---|
password | Set the password part of a URL |
A String representing the password part of the URL.
The following code shows how to get the password part of a link.
<!DOCTYPE html>
<html>
<body>
<!--from w w w . j a va2s . c o m-->
<p><a id="myAnchor" href="https://userName:password@www.example.com">Example link</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = document.getElementById("myAnchor").password;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to change the password part of a link
<!DOCTYPE html>
<html>
<body>
<!-- w w w .j ava 2s . c om-->
<p><a id="myAnchor" href="https://userName:password@www.example.com">Example link</a></p>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("myAnchor").password = "Password101";
document.getElementById("demo").innerHTML = "changed";
}
</script>
</body>
</html>
The code above is rendered as follows: