The read-only origin
property returns the protocol, hostname and port number of a URL.
origin |
Yes | No | Yes | Yes | Yes |
var v = location.origin
A String type value representing the protocol, the domain name or IP address, and port number.
<!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: