JavaScript location.host vs location.hostname Last Updated : 05 May, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will learn about how to get information related to the webpage like hostname, port number, etc. We will also see the difference between the location.hostname and location.host.location object is used to get information about the current web page. host and hostname are properties of location objects.location.hostname: This property will return the domain name of the web page.Syntax:location.hostnameReturn value: It returns a string representing the domain name or IP address.If this is our URL,https://www.geeksforgeeks.org:8080/ds/heapWhen we call location.hostname, This will return.www.geeksforgeeks.orgExample : JavaScript console.log("hostname : " + location.hostname); location.host: This property also returns the same hostname but it also includes the port number. In case, if the port number is not available, then it will just return the hostname.Syntax: location.hostReturn value: It returns a string representing the domain name and port number.If this is our URL,https://www.geeksforgeeks.org:8080/ds/heapWhen we call location.host, This will return.www.geeksforgeeks.org:8080Example : JavaScript console.log("host : " + location.host); location.hostname location.host It is a property of a location object.It is also a property of a location object.It returns the domain name of the current webpage.It returns the domain name as well as the port number (if available) of the current webpage.The return value is of String type.The return value is of String type.Ex: www.abc.comEx: www.abc.com:8080 Comment More infoAdvertise with us Next Article HTML DOM Location hostname Property H hrtkdwd Follow Improve Article Tags : Difference Between JavaScript Web Technologies JavaScript-Properties Web Technologies - Difference Between +1 More Similar Reads How to set location and location.href using JavaScript ? In this article, we will set the location and location.href using Javascript.Both location and location.href are used to set or return the complete URL of your current page. They return a string that contains the entire URL with the protocol.Syntax:location = "https://www.geeksforgeeks.org";orlocati 1 min read JavaScript | window.location and document.location Objects window.location and document.location: These objects are used for getting the URL (the current or present page address) and avert browser to a new page or window. The main difference between both is their compatibility with the browsers. The window.location is read/write on all compliant browsers. T 2 min read HTML DOM Location hostname Property The Location hostname property in HTML is used to return the hostname of the current URL. The Location hostname property returns a string that contains the domain name, or the IP address of a URL. Syntax: It returns the hostname property. location.hostname It is used to set the hostname property. lo 1 min read JavaScript Location protocol Property A network protocol defines rules and conventions for communication between network devices. By adopting these rules, two devices can communicate with each other and can interchange information. The protocol property sets or returns the protocol of the current URL, including the colon (:). Syntax: lo 1 min read How to parse a URL into hostname and path in javascript ? We can parse a URL(Uniform Resource Locator) to access its component and this can be achieved using predefined properties in JavaScript. For Example, the first example parses the URL of the current web page and the second example parses a predefined URL. Example 1:This example parses the URL of the 1 min read How to parse URL using JavaScript ? Given an URL and the task is to parse that URL and retrieve all the related data using JavaScript. Example: URL: https://www.geeksforgeeks.org/courses When we parse the above URL then we can find hostname: geeksforgeeks.com path: /courses Method 1: In this method, we will use createElement() method 2 min read Like