0

On page 1 I have a button with onClick="window.location.href='Rendering.html?myVar1=3'" Then I am hoping to use the myVar1 value here in page 2 (Rendering.html) functions.

In page 2, I have:

var qs = new querystring();
var slideIndex = qs.get("myVar1")
showSlides(slideIndex);

However this doesn't seem to work.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • 1
    Take a look here: https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters – Nir Tzezana Mar 03 '19 at 22:43
  • 1
    Possible duplicate of [How can I get query string values in JavaScript?](https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Adam Chubbuck Mar 03 '19 at 22:53

1 Answers1

0

Take a look at this answer: How can I get query string values in JavaScript?

Function I found helpful:

function getParameterByName(name, url) {
  if (!url) url = window.location.href;
  name = name.replace(/[\[\]]/g, '\\$&');
  var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
      results = regex.exec(url);

  if (!results) return null;
  if (!results[2]) return '';

  return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
Jack Templeman
  • 344
  • 1
  • 9