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

4 thoughts on “JavaScript location”

  1. 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!

    View Comment
  2. 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!

    View Comment
  3. 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.

    View Comment

Leave a Reply

Your email address will not be published.

4 × 3 =