HTML | DOM Location origin Property

The DOM Location origin Property in HTML is used to return the protocol, hostname and port number of a URL. This is a read-only property.

Syntax:

location.origin

Return Value: This method returns a String value representing the protocol, the domain name (or IP address) and port number. The URL’s having the ‘file://’ protocol may return different values depending on the browser.



Note: Some browsers may not display the port number.

Below examples illustrate the above method:

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>DOM Location Origin Property</title>
</head>
  
<body>
    <h1 style="color: green">GeeksforGeeks</h1>
    <b>DOM Location Origin Property</b>
    <p>
      Click on the button to get the location
      origin of the page:
    </p>
  
    <button onclick="getOrigin();">
        Get Location Origin
    </button>
  
    <p>The location origin of this page is:</p>
  
    <div class="location"></div>
  
    <script>
        function getOrigin() {
            let loc = location.origin;
            document.querySelector('.location')
                .innerHTML = loc;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before clicking the button:

  • After clicking the button:

Supported Browsers: The browser supported by DOM Location origin property are listed below:

  • Google Chrome
  • Internet Explorer 11.0
  • Firefox
  • Opera 15.0
  • Safari


My Personal Notes arrow_drop_up

Technical Writer Lets have an update

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.