0

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.

easyX
  • 73
  • 1
  • 1
  • 6

2 Answers2

0

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?

Community
  • 1
  • 1
Cymen
  • 14,079
  • 4
  • 52
  • 72
0

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:

  1. you can redirect the browser to the new changed link using
    window.location='?q=changed_search'

  2. 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.

Tomer W
  • 3,395
  • 2
  • 29
  • 44