JavaScript location

In this article I wrote about the location object in JavaScript and what are the different between them.

Host

This two prints the host name, the different between them are that only host is with the port number from the host.

as example:

and we get this:

 

Port

If you just want to get the Port you could use this:

as example:

and we get this:

Together with “location.host” and “location.port” you could get “location.hostname”.

 

Protocol

To get the Server protocol you just need this:

as example:

and we get this:

 

Href,Origin and Pathname

To get some other URL information run this:

as example:

and we get this:

Href just returns the URL with the pathname, origin just the URL without the pathname, pathname just the path behind the URL and at least the search parameter returns the parameters behind the “?”.