2

I want to change the url or query string without reloading the page...

I have used the QUERY STRING OBJECT plugin for jquery

I have this example page in which on click of a album it should change the query string...

Now i can change the url using the code

window.location.href =  $.query.set('aid', a_id);

but it goes for reloading the page...

and this code does not have any effect

 var newUrl =  $.query.set('aid', a_id);

How can do without reloading the page...

how can i do without reloading the page...

Thanks
Pradyut
India

2
  • 2
    What you're asking to do doesn't make sense. You cannot change the address in the browser's address bar without reloading the page. Changing the query string changes the address and necessarily requires the page to reload the new address. Commented May 13, 2010 at 19:16
  • 2
    This does make sense. He's looking for the hash property, as explained here: ajaxpatterns.org/Unique_URLs Commented Sep 30, 2010 at 4:33

4 Answers 4

7

You cannot change the query string without reloading the page.

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

1 Comment

This should be the accepted answer. There is a difference between query and fragment as described here
3

I got the solution...

change the query string after a #

you can get and set the query string using javascript

location.hash = 'something=anything'

Thanks
Pradyut
India

3 Comments

I don't understand - how does this help you? You aren't changing the querystring - you're changing the anchor.
read hash with the above javascript, modify dom elements with js calling ajax data...
this isnt changing the query string it is changing the anchor
2

If you just want to change the Hash, your approved solution might work ok. However, to modify the query you will need to use the history.pushState. It works only on web browsers with the HTML5 History API, though.

if (history.pushState) {
    var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?myNewUrlQuery=1';
    window.history.pushState({path:newurl},'',newurl);
}

I tested, and it worked fine. It does not reload the page, but it only allows you to change the URL query. You would not be able to change the protocol or the host values.

For more information:

http://diveintohtml5.info/history.html

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

Comments

0

Another solution which you may find useful is the BBQ plugin for jQuery. Here's an example: http://benalman.com/code/projects/jquery-bbq/examples/fragment-basic/

Comments

Your Answer

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.