Get URL Parameter Values from Query String in Javascript - Step by Step Guide

Опубликовано: 07 Апрель 2019
на канале: Mr. Virk Media
20,504
147

Full Article: https://mrvirk.com/get-url-parameter-...
What is Query String ? https://mrvirk.com/what-is-url-query-...
Related Video:    • Programmatically passing URL Paramete...   (Programmatically passing URL Parameters to IFrame src using JavaScript)

We will learn How to get URL Parameter values ?geo=UK&size=300×600 in Javascript ?

This is the most latest and safe solution you can find in 2019.

How to approach the problem ?
We will solve the problem using URL Object, which is basically getting the url of the page when it loads, then passing it though the URL object, like this

var url = new URL(“https://mrvirk.com?geo=UK&size=300×600”);

Solution Code in Javascript
Follow the code below on Codepen and insert the parameter in codepen url to see results in console.

Link to Code: https://codepen.io/virksaabnavjot/pen...