简体   繁体   中英

display Data from URL to html

This is the URL

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.

<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

What javascript code can I use? 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"

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