Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the difference between window.location.host and window.location.hostname [duplicate]

Tags:

javascript

They both seem to give me the same thing (the domain name currently executing the script).

So what's the difference (if any) and where should each be used?

like image 433
Thomas Clayson Avatar asked Jul 01 '11 14:07

Thomas Clayson


People also ask

What is window location host?

The window.location.hostname property returns the name of the internet host (of the current page).

What is location host?

The location. host property returns the host (IP adress or domain) and port of a URL. The location. host property can also be set, to navigate to the same URL with a new host and port.

What is the difference between window location and document location?

window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).


1 Answers

MDN Web Docs - window.location

host....: the host name and port number. [www.google.com]:80
hostname: the host name (without the port number or square brackets). www.google.com

like image 95
mplungjan Avatar answered Oct 19 '22 15:10

mplungjan