Location origin Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Location


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

This property is read-only.

Return Value

A String, representing the protocol, the domain name or IP address and port number of the URL.

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<button onclick="myFunction()">Test</button>

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

function myFunction() {/*from  w  w  w .  j  a  v a 2  s  .c  om*/
    var x = location.origin;
    document.getElementById("demo").innerHTML = x;


Related Tutorials