Javascript provides multiple ways to get the current URL that is displayed in the address bar. I listed them below:


You can use any of the above mentioned methods to get the current URL in address bar, But all these methods relies on window.location.

It is observed that document.URL is  bugged in Firefox 12, But in latest version it doesn’t have any issues.

Generally an URL has following properties:


 Protocol  -- Specifies the protocol name be used, Ex: http / https

 Hostname  – Domain name which provides the resource, Simply speaking it is website name.

 Port  -- A port number used to recognize a specific process to which an Internet or other network message is to be forwarded when it arrives at a server.

 Pathname  – It is the resource location within the host, Ex: /index.html

 Query  – A query string is what follows after the pathname, it provides additional information to the resource to process the request. Ex:/index.html?search=actors

 Hash  – This is the anchor portion in a URL, includes hash(#) sign. Ex: /index.html#title


Comments (0)
Leave a Comment

loader Posting your comment...