Anchor origin Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Anchor


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>

<p><a id="myAnchor" href="">Example link</a></p>

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

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

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


Related Tutorials