Javascript Reference - Location origin Property








The read-only origin property returns the protocol, hostname and port number of a URL.

Browser Support

origin Yes No Yes Yes Yes

Syntax

var v = location.origin

Return Value

A String type value representing the protocol, the domain name or IP address, and port number.





Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--   ww  w  . ja  va2s  .  c  o m-->
    var x = location.origin;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: