Malfist
Malfist

Reputation: 31795

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 the page they want to view.

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

Upvotes: 2

Views: 483

Answers (2)

Rahul Prasad
Rahul Prasad

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

uvita
uvita

Reputation: 4124

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

Upvotes: 2

Related Questions