• hi,

    How can I preserver the url paramaters on other pages ?

    1/ So we enter the site on:
    example.be/?source=abc

    2/ we click on a button on the page, and this should lead to:
    example.be/page2/?source=abc

    I searched online for hours, but can’t find a solution that works.

    Thanks

Viewing 1 replies (of 1 total)
  • Javascript: 1st part Checks URL for queries.
    2nd part attaches route function to button with queries add to URL
    You will need to adjust for your URLs.

    ////////1st part
    *Check Query Strings on URLs*
    function getQueryVariable(variable) {
    var query = window.location.search.substring(1)
    var vars = query.split(“&”);
    var blank = “blank”
    for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split(“=”)
    if(pair[0] == variable){
    if(pair[1].indexOf(‘%20’) != -1){
    console.log(pair[1].indexOf(‘%20’))
    var fullName = pair[1].split(‘%20’)
    console.log(fullName)
    return fullName[0] + ‘ ‘ + fullName[1]
    }
    else {
    return pair[1];

    }
    }
    }
    return(false)
    }

    /////////2nd part

    var allqs = location.search;
    var pageBase = “https://yoursite.com/register&#8221; + allqs;
    // var slash = “\/”;
    // var sidVar = “”;

    function leaveFunc() {
    console.log(“outgoingbtn clicked!!”);
    if(allqs == “”){
    console.log(“There are no queries on the URL”);
    allqs = “?provider=somecare”;
    console.log(“Here is the allqs with the default” + allqs);
    pageBase = “https://yoursite/register&#8221; + allqs;
    }else{
    console.log(“Yes, There are queries on the URL”);
    console.log(“allqs is “+ allqs);
    pageBase = “https://yoursite/register&#8221; + allqs;
    }
    window.open(pageBase);
    }

Viewing 1 replies (of 1 total)
  • The topic ‘keep url paramater on pages’ is closed to new replies.