Access URL params

URL parameters or sometimes called query strings is a concept of structuring additional information in the URL. The parameters follow a “?” and multiple parameters are separated by the ‘&’.

These parameters are great ways to include additional data that is readily available and accessible at all times. For example, if our url looked something like this

Being able to target the keyword from the URL could be very useful in certain cases so quickly let’s see how to do that.

window.location.search grabs the url search params which is everything after the ‘/’ or main domain. After saying the params to a variable we can then parse the variable with the urlParams.get() method.

If we do this correctly we will get access to a string called “cat_memes” under the variable watch.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store