Open In App
Related Articles

HTML | DOM Location origin Property

Improve Article
Save Article
Like Article

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. 



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: 



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


  • Before clicking the button:


  • After clicking the button:


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

  • Google Chrome 8.0
  • Edge 12.0
  • Internet Explorer 11.0
  • Firefox 21.0
  • Opera 15.0
  • Safari 5.1
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 05 Jul, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials