开发者

How can Maintain browser history in ASP.NET AJAX

开发者 https://www.devze.com 2023-02-05 11:18 出处:网络
How can I maintain the browser history while perfo开发者_如何学JAVArming ASP.NET AJAX asynchronous postback operations?My answer may not necessarily relate to ASP.NET, but ajax in general.

How can I maintain the browser history while perfo开发者_如何学JAVArming ASP.NET AJAX asynchronous postback operations?


My answer may not necessarily relate to ASP.NET, but ajax in general.

There are many neat plugins for jQuery which allow you to maintain browser history when using ajax to load content on the page.

The one I recommend is jQuery History Plugin - http://tkyk.github.com/jquery-history-plugin/

Basically you'll have have the URL's built in this way:

http://yourpage.com/#page1
http://yourpage.com/#page2

The plugin will detect when the URL changes, and the browser does not try to re-load the page since there's a hash in the address. So, when the plugin detects the address change, then you can do whatever you want. For example the address is changed to http://yourpage.com/#page1 and then jQuery History would detect the change and you could get the #page1 string from the event that triggers the address change. Then you know, aha! I have #page1, then I should do that ajax operation.

It's also really simple to add a page to the history with jQuery History, you simply do:

$.history.load(url);

There are many good demos on http://tkyk.github.com/jquery-history-plugin/#demos and http://www.serpere.info/jquery-history-plugin/samples/

I hope this helps, good luck!

0

精彩评论

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