Javascript Reference - HTML DOM Anchor origin Property








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

This property is read-only.

Browser Support

origin Yes Yes Yes Yes Yes

Syntax

anchorObject.origin 

Return Value

A String representing the protocol, the domain name or IP address and port number of the URL.





Example

The following code shows how to get the protocol, hostname and port number of a link.


<!DOCTYPE html>
<html>
<body>
<!-- ww w.  ja  v a2 s.  co  m-->
<p><a id="myAnchor" href="http://www.example.com:1234/test.htm#part2">Example link</a></p>
<button onclick="myFunction()">test</button>

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

<script>
function myFunction() {
    var x = document.getElementById("myAnchor").origin;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: