Get the parts of the URL in Javascript

It's very useful to understand on how to get either the full or parts of the URL within the browser in Javascript. In this post I am going write a couple snippets on how you can extract parts of the URL.

Throughout this post I will be using the example URL below:

http://www.ssweb.co.uk/get-the-parts-of-the-url-in-javascript/?x=123&y=456&z=789

A URL is built up of different sections, these are commonly;

  • Protocol
  • Host
  • Pathname
  • Search

We can very easily access these values by using Javascript, and below is exactly how...

#

AuthorShaun Swales

Web developer turned QA Software Engineer.