Anchor origin Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor

Description

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

This property is read-only.

Return Value

A String, representing

  • the protocol (including ://),
  • the domain name (or IP address) and
  • port number (including the colon sign (:) of the URL.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p><a id="myAnchor" href="http://www.example.com:8080/test.htm#part2">Example link</a></p>

<button onclick="myFunction()">display the origin of the link above</button>

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

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

</body>
</html>

Related Tutorials