Reputation: 31795
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 the page they want to view.
Is there a way I can update the URL without redirecting the page?
Upvotes: 2
Views: 483
Reputation: 8222
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.
Upvotes: 4