开发者

Set current url with jQuery?

How do change the url shown with the jQuery? With pagination, I do an ajax call to get the next page, bu开发者_Python百科t I want to update the url for bookmarking purposes. How do I do that?


You'd do it with either the HTML5 History API or hash tags.


You should consider using the address plugin: http://www.asual.com/jquery/address/

Supports deep linking and updates the address for you with a simple function call.


How far do you want to go? Do you want to change index.html to about.html or do you want to change it to index.html#about.html and have JavaScript change the page?

If you want to do the first you will need to use the HTML5 history API. Be aware that it only works in some browsers. I would recommend reading Dive Into HTML5's History API tutorial to understand all the details of how it works, but if you want to jump right into it, you can try the History.js jQuery plugin.

If you need support for older browsers, consider the hashchange event and the HashChange jQuery plugin. Every time you change pages, you can set location.hash to the page you want to map.

In both cases, you need to be aware that you're adding pages to the history and will need to monitor the events provided by the plugins. Otherwise, when the user clicks back, the URL will change but the page won't.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜