Tag Archives: URL Parts

Get various parts of URL using JavaScript

Recently I wanted to get a domain name of the page on which I was currently on. I was trying to parse the entire URL of the page and then parse it using regular expressions etc. to get the domain name. I was able to get the required information using this method, but then I thought that this is something for which there should be an easier way, and indeed there is an easier way.

We can use the Location Object to get all the various parts of the URL. (e.g. window.location.href to get the entire URL)

Note: There is no public standard that applies to the location object, but all major browsers support it.
Read more »

Parts of URL

We see so many URLs everyday, but do we know what are the parts of an URL, what does each part means? In this post I will discuss the various parts of the URL.

An URL may consists of as many as 6 parts. The different parts of the URL are:

scheme://domain:port/path?query_string#fragment_id

Some people refer to the parts as:

protocol://hostname:port/pathname?search#hash

Read more »