How To Get Query String From Url With Javascript? – POFTUT

How To Get Query String From Url With Javascript?

Query string is part of URL. After question mark query string begins with simple key-value pairs. Popular JavaScript frameworks provide libraries to get query string with JavaScript. But how can we get it with pure JavaScript without using any JavaScript framework?

getParameterByName() Function

First we create a function to to get, parse the URL and get values with keys.

  • Here we create a function name getParameterByName.
  • We provide key with name parameter.
  • url parameter is optional we can pass it if we need.
  • function returns value of the key.

Usage of getParameterByName Function

Usage is very simple like a dictionary structure.

  • This our sample URL

  • We use our function getParameterByName with the key exists in URL.
  • size will be 15 without example URL.

 

How To Get Query String From Url With Javascript? Infografic

How To Get Query String From Url With Javascript? Infografic

How To Get Query String From Url With Javascript? Infografic

LEARN MORE  Search Text Files Content With Findstr Command In Windows

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)