0

I think this is simple but can't seem to find the answer.

In our autoresponder, when a contact clicks a link to visit a page, the contact id and email are passed through to the next page.

So by clicking an email, the contact lands on page.com/1/?id=123&email=name@gmail.com

On that page, and there is a button to click to go to the next page...

what do I need to do so the parameters pass to the next page and the contact lands on page.com/2/?id=123&email=name@gmail.com?

Thanks for the help!

Chris
  • 29
  • 4
  • 1
    Have you written any code to try and resolve this? – Vasan Mar 23 '18 at 17:08
  • There are a lot of solutions, but I cannot provide the solution. because you didn't give any code. – kyun Mar 23 '18 at 17:09
  • I'll be more descriptive to help... I am using LeadPages Drag and Drop page builder. The contact clicks a link inside an email and lands on baseurl.com/lesson-1 with ?id=[contactid]&email=[contactemail]. There is 1 button on the page that reads "View Next Lesson" and 1 line for me to paste the next URL (baseurl.com/lesson-2) into. I want those passed through to the next page, which I believe means I need to append a variable to the end of the url. I am early into learning front-end dev, so I apologize if I haven't been perfectly descriptive so far. – Chris Mar 23 '18 at 19:07

2 Answers2

0

If the page number is all that changes:

button.addEventListener('click', () => {
  const currentPage = Number(window.location.href.match(/\d+/));
  window.location.href = window.location.href.replace(/\d+/, currentPage + 1);
});
CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • The question is pretty vague and there's no code provided. What if it was a submit button sending form data? Also, the URL may have other numbers – Vasan Mar 23 '18 at 17:11
  • The question looked to be pretty clear to me - "from a page such as `page.com/1/?id=123`, how to get a button click to land on `page.com/2/?id=123`"? The parameters are already in the URL when on the first page, so it says. – CertainPerformance Mar 23 '18 at 17:13
  • I wouldn't recommend this. If the url has to change, which is not uncommon, this will break. – Train Mar 23 '18 at 17:43
0

Edit: here is a function to get the querystring parameters from This link

    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));

}

If you already know the base url, and have the parameters just combine the two and redirect.

document.getElementById("myButton").onclick = function () {
     var url = "page.com/2"; //get your base url how ever you're doing it.
     var queryString = "?id=123&email=name@gmail.com";
     var fullUrl = url + queryString;
     window.location.href = fullUrl ;
};
Train
  • 3,420
  • 2
  • 29
  • 59