开发者

Bookmarkable Ajax

I'm paginating a list of items, and currently the page listed on page load is set by a GET variable (e.g. www.example.com/page.html?page=2). I want to switch it to ajax, but I'm worried users won't be able to bookmark开发者_JAVA百科 the page they want to view.

Is there a way I can update the URL without redirecting the page?


Use hash

Your website is www.example.com/page.html

Part I.

When you load page two using ajax add a hash to the url www.example.com/page.html#page2 You can do that using javascript window.location.hash = "page2". Now users can bookmark www.example.com/page.html#page2

part II.

When a user request a page say, www.example.com/page.html#page2 You can read the hash using javascript.

var myHash = window.location.hash If myHash is empty load the page normally. If it contains "page2", then load the content of page2.


Yes, with a hash in the url. You can learn more here.

You can also find a nice jquery plugin for that purpose here.

Regards

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜