How to get a value in the javascript link

2

Hello! How can I get certain values in a link? I have a url like this: slide.html? title = Name & volume = 12 however I just want to display the volume value on an h2.

My Code:

$(document).ready(function(){
  var html = '';

  var query = location.search.slice(1);
  var partesDaQuery = query.split("&");
  var json = {};

    partesDaQuery.forEach(function(partes){
      var chaveValor = partes.split('=');
      var paramsKey = chaveValor[0];
      var paramsValue = chaveValor[1];
      json[paramsKey] = paramsValue;

      html += '<h2></h2>';
      console.log(paramsValue);
        });
    $("#lista").html(html);

  });
    
asked by anonymous 15.12.2017 / 22:45

1 answer

2

There are several ways to get the string, one of them is using split('=').pop() if the string you want to capture from the URL is always the last one after = :

Page URL: slide.html?titulo=Nome&volume=12

var string = location.href.split("=").pop();
                                    
15.12.2017 / 23:08