简体   繁体   English

显示从 URL 到 html 的数据

[英]display Data from URL to html

This is the URL这是网址

https://www.mystore.com/receipt.html?total=100&orderid=ab123 https://www.mystore.com/receipt.html?total=100&orderid=ab123

I want to display value of 'total' and 'orderid' in the above url to the below code in a html page.我想将上面 url 中“total”和“orderid”的值显示到 html 页面中的下面代码中。

<img src="https://getcurcumin.go2cloud.org/aff_l?order=[orderid]&amount=[total]" width="1" height="1" />

so the actual code will read as所以实际的代码将读作

<img src="https://getcurcumin.go2cloud.org/aff_l?order=ab123&amount=100" width="1" height="1" />

after taking values from the URL从 URL 取值后

What javascript code can I use?我可以使用什么 javascript 代码? Please suggest.请建议。

Thanks谢谢

Try This:尝试这个:

<script type="text/javascript">
var total = getQueryVariable("total");
var orderid = getQueryVariable("orderid");
alert(total);
alert(orderid);
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
}
</script>
var query = window.location.search.split('&'),
    total = query[0].split('=')[1],    // "100"
    orderid = query[1].split('=')[1];  // "ab123"

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

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