-1

I have a query string (example) ?something=1&something=3 I want to find and then add these parameters to a new URL and goto that URL on button click event.

I can find the query string using var x =location.search; but don't know how to add to a new URL, then use the function on button click event.

Many thanks in advance!

maio290
  • 5,118
  • 1
  • 14
  • 29

1 Answers1

0

Assuming you have a button like that:

<button type="button" onclick="redirect('mysite.html')">

the redirect function can look like this:

function redirect(target)
{
    window.location.href = target+window.location.search
}

But basically, this problem is easy to solve by divide and conquer:

How to get the value from the GET parameters?

How do I redirect to another webpage?

How to Call a JS function using OnClick event

How to prevent buttons from submitting forms

maio290
  • 5,118
  • 1
  • 14
  • 29