-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!

1
  • Where have you searched for the answer? There are plenty of explanations of this on the web. Commented Jul 20, 2020 at 15:37

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.