Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    How to use URL parameter ?

    Cloud CMS (Pagebuilder, Blog, Shop, Newsletters, Code Editor)
    4
    6
    559
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Camille Guitard
      Camille Guitard last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • J
        jbenguira last edited by

        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

        1 Reply Last reply Reply Quote 0
        • Camille Guitard
          Camille Guitard last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • Joseph Benguira
            Joseph Benguira last edited by Joseph Benguira

            Just drop a bloc of javascript on your page (+ > ELEMENTS > SOURCE CODE > JS)
            and inside you can paste this function

            function 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

            1 Reply Last reply Reply Quote 1
            • Pierre SULPICE
              Pierre SULPICE last edited by

              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 😉

              1 Reply Last reply Reply Quote 3
              • Camille Guitard
                Camille Guitard last edited by

                Thanks for all the help, thanks to you I managed to do what I wanted, and I learned some things along the way !

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post