change url or query string wihout reloading using jquery plugin
I want to change the url or query string without reloading the page...
I have used the QUERY STRING OBJECT plugin for j开发者_如何学Cquery
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 IndiaYou cannot change the query string without reloading the page.
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
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
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/
精彩评论