Javascript Reference - HTML DOM Area password Property








The password property sets or gets the password part of the href attribute value.

Example: https://userName:myPass@www.example.com.

Browser Support

password Yes Yes Yes Yes Yes

Syntax

Return the password property:

var v = areaObject.password 

Set the password property:

areaObject.password = password;

Property Values

Value Description
password Set the password part of a URL




Return Value

A String representing the password part of the URL.

Example

The following code shows how to get the password part of the URL for a specific area in an image-map.


<!DOCTYPE html>
<html>
<body>
<!--from  ww w. j  a  v  a  2  s.c  o m-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
   height="126" usemap="#myImageMap">

<map name="myImageMap">
  <area id="myArea" shape="circle" coords="124,58,8" 
  alt="myImage" href="https://userName:myPass@www.example.com">
</map>

<p id="demo"></p>

<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myArea").password;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to change the password part of a specific area in an image-map.


<!DOCTYPE html>
<html>
<body>
<!--from   w ww.j a  v a  2s  .c o m-->
<img src="http://java2s.com/style/demo/border.png" width="145" 
     height="126" usemap="#myImageMap">

<map name="myImageMap">
  <area id="myArea" shape="circle" coords="124,58,8" alt="myImage" 
        href="https://userName:myPass@www.example.com">
</map>

<p id="demo"></p>

<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("myArea").password = "newPassword101";
    document.getElementById("demo").innerHTML = "changed";
}
</script>

</body>
</html>

The code above is rendered as follows: