JavaScript window.location.hostname Property

You are Here:

JavaScript window.location.hostname Property

The window.location.hostname property returns the domain name of the web host.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> document.write("Page hostname: "+window.location.hostname); </script> </body> </html>

Syntax

window.location.hostname

Return Value

ValueExplanation
StringReturns a string representing the domain name of the web host.

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var txt = ""; txt += "<p>Page location: "+window.location.href+"</p>"; txt += "<p>Page hostname: "+window.location.hostname+"</p>"; txt += "<p>Page path: "+window.location.pathname+"</p>"; txt += "<p>Page protocol: "+window.location.protocol+"</p>"; txt += "<p>Port number: "+window.location.port+"</p>"; document.write(txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author