JavaScript location

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


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:



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


as example:

and we get this:


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



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 “?”.

4 thoughts on “JavaScript location”

  1. What’s up, of course this article is in fact pleasant and I have learned
    lot of things from it concerning blogging. thanks.

  2. Hi there! This is my first comment here so I just wanted to give
    a quick shout out and say I really enjoy reading your blog posts.
    Can you suggest any other blogs/websites/forums that go over the same topics?
    Thanks for your time!

  3. This design is spectacular! You certainly know how to keep a reader
    entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Great
    job. I really loved what you had to say, and more than that,
    how you presented it. Too cool!

  4. Thanks for any other informative web site. The place else may
    I get that kind of information written in such a perfect way?

    I’ve a mission that I’m just now working on, and I’ve been at the
    look out for such info.

Leave a Reply

Your email address will not be published.

three × 2 =