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
a source to share
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
a source to share
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/
a source to share