REMINDER
How to use URL parameter ?
-
Hello,
I want to pass a value using URL parameter, but I don't understand how I am supposed to retrieve the value I sent once I am on my second page.
-
Hey Camille, you need to use javascript to read the url parameters. There is tons of tutorials about that on internet.
https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters
-
Hello jbenguira, thanks for the answer ! I looked up how to do it with JavaScript, but after some test I now feel like my page isn't reading Js, so I'm wondering how I should use it and if there's somewhere I should place my Js code ?
I tested just creating a variable and dislpaying it in a pop-up using alert() but even that is not working.
-
Just drop a bloc of javascript on your page (+ > ELEMENTS > SOURCE CODE > JS)
and inside you can paste this functionfunction getUrlParam(paramName) { var match = window.location.search.match("[?&]" + paramName + "(?:&|$|=([^&]*))"); return match ? (match[1] ? decodeURIComponent(match[1]) : "") : null; } alert( getUrlParam("myparam") );
Then save and publish that page and open your page url and add a param like this ?myparam=yourvalue
But all this is better explained by begginers lessons of javascript, maybe you can start here:
https://javascript.info/and more precisely SearchParams part on that page: https://javascript.info/url
-
If you don't care about IE11, this is even enough :
(new URL(window.location.href)).searchParams.get("param_name");
I like this writing because it's easy to even add it in cloud backend forms as a javascript line to send it to your backoffice.
You'll get null if the name isn't found.Warning : Don't mix up query string and fragment ofc when you do that
-
Thanks for all the help, thanks to you I managed to do what I wanted, and I learned some things along the way !