Javascript DOM HTML Anchor origin Property get

Introduction

The origin property returns the protocol, hostname and port number of the href attribute value.

This property is read-only.

Return the protocol, hostname and port number of a link:

var x = document.getElementById("myAnchor").origin;

Click the button to display the origin of the link.

View in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.java2s.com:1234">Example link</a></p>

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*from w  ww  . j a  v a  2 s. c om*/
  var x = document.getElementById("myAnchor").origin;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related