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:

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.
You might also like