I used query string now to adress some special (dynamic) content. Now is my question: Is it possible to change the actual query by JS when i change the dynamic content, so that i could refresh the site with the same content and not with the default query values.
-
Look into the HTML5 History API. – Benjamin Gruenbaum Apr 18 '14 at 01:11
-
Tanks very much :D This is what i was looking for. I already use it now. If you want you can write an answer, so i can accept it. – easyX Apr 21 '14 at 17:54
2 Answers
Yes, you can achieve this by changing window.location.href
if you want the browser to go to a different URL. For example, go to http://google.com and now open the JavaScript console of your browser and put:
window.location.href = 'http://google.com/?q=abc'
If you only want to change part of the URL (query string), there are a bunch of ways to do that. You can do it manually and set a whole new URL or use libraries/plugins to help you do this. How to parse the query string: How can I get query string values in JavaScript?
i hope i understood the question right...
i guess that browsers wont like to allow you to touch their Request object...
but i think of two methods:
you can redirect the browser to the new changed link using
window.location='?q=changed_search'
in your other scripts, dont reference the real Querystring, but a (private to the page) copy of it which you can change wherever you want.
Note: QueryString is mostly input from the user, and i dont think it should be needed to change without the page being resubmitted (as suggested in 1).
cheers.

- 3,395
- 2
- 29
- 44