Change url or query string wihout on load using jquery plugin

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

I used the QUERY STRING OBJECT plugin for jquery

I have this page where when the album is clicked 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 is meant to reload the page ...

and this code has no effect

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

      

How to do it without reloading the page ...

how can i do without page reload ...

Thank you
Praduti
India

+2


a source to share


4 answers


I got a solution ...

change the query string after #

you can get and set the query string using javascript



location.hash = 'something=anything'

      

Thank you
Praduti
India

+3


a source


You cannot change the query string without reloading the page.



+7


a source


If you want to change the Hash, your approved solution might work fine. However, to change the request, you will need to use history.pushState. However, it only works with web browsers with HTML5 history API.

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 does allow changing the url request. You cannot change the protocol or 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

+2


a source


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

0


a source







All Articles