Skip to content
Advertisement

Grab query string value from URL using Javascript

I want to visit https://example.com/?GCLID=test123 and store whatever is in GCLID in a variable.

How do I do this? The following keeps returning null

JavaScript

Advertisement

Answer

You have to take the part after ‘?’ in new URLSearchParams, see below example for same, i.e you will pass window.location.search like this

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement