简体   繁体   中英

passing actual URL parameters to a button

I'm working on a web funnel , that i would like to track starting from step number #1 . I'm trying to pass URL parameter for example :

https://mywebsite.com/###/######.html ? subid=160445 &eng_source=160445&eng_subid=null&eng_click=1d1ba0f6784b4c36918f087b616a3366

i want to pass the "subid=#" to the next destination which is button link so it becomes: https://landing.mywebsite.com/2scstep.html?subid=160445

or what ever "subid" was there before .

i just need some instruction from where to start adding this or what language should i work with .

Thanks A lot .

OK, lets imaging you have button on the page, which is

<a id="button" href="https://landing.mywebsite.com/2scstep.html">
Take me to new destination
</a>

If I understood you question correctly, you want change the destiantion of the button (href) so it becomes oldhref + '?subid=#'

It can be done in many techniques in javascript. Simpliest way is to install jquery, and then make smething like this

//Wait untill whole document is loaded
$(document).ready(function(){

  //You now is on the page, that has url e.g. `href` + `?subid=12345`
  // you got to get you subid var to javascript

  //Get whole url
  var currentHref = window.location.href;

  //Get only params part, by splitting string by ? and taking second part
  var currentHrefParamsPart = currentHref.split("?")[1];

  //Now get all params to array (there can be lots of params)
  var paramsArray = currentHrefParamsPart.split("&");

  //Now get subid value

  var subid = false; //its not known yet
  paramsArray.each(function(params){
     var key = params.split('=')[0]

     if (key == "subid") {
         var subid = params.split('=')[1]; //We got it
     }
  })

  //Now you gotta change href attribute of the button if subid was found
  if (subid) {

    var $button = $("#button");
    var oldHref = $button.attr("href"); //get the old href
    var newHref = oldHref + "?subid=" + subid; //make new href
    $button.attr("href", newHref);
  }

})

It is not working code, there could be mistakes or tyopos, I wrote it to give you an idea how to achieve the result, what techiques and languages should be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM