The origin
property returns the protocol, hostname and
port number of the href attribute value.
This property is read-only.
origin |
Yes | Yes | Yes | Yes | Yes |
anchorObject.origin
A String representing the protocol, the domain name or IP address and port number of the URL.
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: