繁体   English   中英

将实际的 URL 参数传递给按钮

[英]passing actual URL parameters to a button

我正在开发一个网络漏斗,我想从第 #1 步开始跟踪。 我正在尝试传递 URL 参数,例如:

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

我想将“subid=#”传递到下一个目的地,即按钮链接,所以它变成: https ://landing.mywebsite.com/2scstep.html?subid=160445

或者之前有什么“subid”。

我只需要一些说明从哪里开始添加这个或我应该使用什么语言。

多谢 。

好的,让我们想象一下页面上有按钮,这是

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

如果我理解你的问题是正确的,你想改变按钮(href)的oldhref所以它变成oldhref + '?subid=#'

它可以通过 javascript 中的许多技术来完成。 最简单的方法是安装jquery,然后像这样制作

//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);
  }

})

它不是工作代码,可能有错误或错别字,我写它是为了让您了解如何实现结果,应该使用哪些技术和语言。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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