0

I want to put a query in a URL using JavaScript, how can I do that?

Horizon_Net
5,9994 gold badges33 silver badges34 bronze badges
asked Jun 26, 2015 at 14:51
2
  • var foo = 'http://example.com?foo=bar' Commented Jun 26, 2015 at 14:57
  • 1
    possible duplicate of Append a param onto the current URL Commented Jun 26, 2015 at 15:02

2 Answers 2

1

Guess, document.location.search is what you're looking for

answered Jun 26, 2015 at 14:58
Sign up to request clarification or add additional context in comments.

Comments

0

This is simple:

location.href += '?ts=true';

Refer: Append a param onto the current URL

answered Jun 26, 2015 at 15:01

4 Comments

is there any away to add just one query? (instead of a infinite loop of queries)?
You should make your question clearer. Could you make some illustration examples?
to do something like this: original: server/myapp.php?id=10 what i want: server/myapp.php?id=10&enabled=true
I think this would be simple: window.location.href + '&enabled=true'

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.