Javascript DOM HTML Anchor username Property set

Introduction

Change the username part of a link:

document.getElementById("myAnchor").username = "newUsername";

Click the button to change the username part of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="https://userName:password123@www.java2s.com">Example link</a></p>
<button onclick="myFunction()">Test</button>
<p id="demo"></p>

<script>
function myFunction() {/*from  w  w  w  .j  a v a2  s . c om*/
  document.getElementById("myAnchor").username = "newUsername";
  document.getElementById("demo").innerHTML = "The username was changed.";
}
</script>

</body>
</html>



PreviousNext

Related