views:

36662

answers:

14

I have found two plugins that enable the browser's back button to work across ajax interactions, but I can't determine which is better and why. The two plugins are history_remote and the history.

The history plug in is simpler and seems to provide all the functionality I need, but I'm not sure I understand enough about them to make an intelligent decision. For my application, I need the plugin to allow the back button to work through ajax interactions, and I need to be able to bookmark the page at any point through the interactions.

Which plug in is best in this scenario and why? Are there any other plug ins that I missed that might be better? Are there any limitations to these plugins that I'm missing (do they not work in certain situations etc)? Any information would be greatly appreciated.

+8  A: 

I'm successfully using history & anchors to make the back/forward buttons work on an AJAX page.

Just define a function in the global scope to get called for every navigation event:

function nav_event(hash) {
  // Some sort of navigation happened, update page
}

$(document).ready(function(){
  $.history.init(nav_event);
  $.history.load('#some_anchor');
}
schmichael
What could this filter through? The use of it?
Coughlin
I have several problems using this. It breaks in chrome when the history reaches 50 entries, it breaks in older versions of chrome in a different way, and it doesn't work in IE6 if you have a '?' in a hash you use. Some of these problems are easy to fix, but the plugin doesn't seem to be very well maintained, and support requests are seemingly going unanswered.
SpoonMeiser
@SpoonMeiser, I too have had issues with others, perhaps try this one http://www.balupton.com/sandbox/jquery-history/demo/
balupton
+1  A: 

There's a third jQuery plugin which also gives you back/forward button support: http://www.overset.com/2008/06/18/jquery-history-plugin/

It doesn't require you to alter your hrefs with hash fragments, although it doesn't give you the bookmarking support you requested it might still be worth checking out.

A: 

Hello first of all forgiveness for my bad English. I tried both and saw that fails in IE with internal links in a page loaded with ajax and this method. Someone know how to solve.

+2  A: 

http://code.google.com/p/reallysimplehistory/

I could not get this to work with jQuery.
Vebjorn Ljosa
+38  A: 

http://www.asual.com/jquery/address/

Rostislav
Despite the lack of explanation, this really is a nice plugin. Its interface actually makes sense, unlike some other plugins, and is dead simple to implement. It also actually works with bookmarking, refreshing, and back/forward, unlike (for instance) "history/remote."
adrian
I too have to chime in and vouch for this one, too. Elegant, and impressively well-documented. All I did was change the links to anchors, and attach a single global callback:$.address.change(function(info) { my_click_func(info.path); });
Luke Dennis
This is (in my opinion) the most robust of the offerings. You can easily port code written for jquery.history to work with this by doing something like: `$.address.change(function(c){my_callback_function(c.value);});`
sholsinger
This is far superior to the jQuery history plugin suggested by @schmichael; it doesn't seem to have any of the same bugs, and seems to be more actively maintained.
SpoonMeiser
hi, i am trying to get address to work with the following:`<a href="#" rel="address:'.$ref.'" onclick="javascript: showJobDetails('.$ref.');"`Where showJobDetails makes an jQuery $.ajax call based on $ref number.
alex
A: 

http://www.overset.com/2008/06/18/jquery-history-plugin/

have a bug..it sometimes call the ajax file twice

edwin
+3  A: 

This one is new and works on all recent browsers :

http://benalman.com/docs/code/files/javascript/jquery/jquery-ba-url-js.html

have fun !

vvo
+13  A: 

I'm really surprised the BBQ plugin by renowned Ben Alman didn't got a mention here http://benalman.com/projects/jquery-bbq-plugin/

dolzenko
It's worth pointing out that there's a great tutorial on using -part of- the BBQ plug-in, by Remy Sharp over at: http://jqueryfordesigners.com/enabling-the-back-button/
David Thomas
@Ricebowl - I might be wrong here but I watched Remy's tut and he starts of using the BBQ plugin, finds he can't tidy up the hash tag so just uses the hashchange event which I don't think requires the BBQ plug-in. I got it to work without the plugin.There's a also good tutorial here msdn.microsoft.com/en-us/scriptjunkie/ff690558.aspx
Nick Lowman
@Nick Lowman, in all honesty, you could well be right. I think I'd watched the tutorial some time before I wrote that comment. Though now I'll have to re-watch, for curiosity's sake...
David Thomas
@Ricebowl - It does the need the plugin - http://stackoverflow.com/questions/116446/what-is-the-best-back-button-jquery-plugin/3342483#3342483
Nick Lowman
If you don't need all of the functionality of the BBQ plug-in and just want the hashcahnge event to work on all browsers then he (Ben Alman) has seperated the code into it's onw plugin here http://benalman.com/projects/jquery-hashchange-plugin/
Nick Lowman
A: 

For a complete AJAX Navigation solution, you may want to check out http://github.com/Panmind/jquery-ajax-nav

vjt
A: 

For completeness of this list, jQueryTools also has one: http://flowplayer.org/tools/toolbox/history.html

Amir
A: 

This worked very well right off - http://flowplayer.org/tools/toolbox/history.html#plugins_tab

And the code is:

<a id="index.cfm?fuseaction=something" href="something">Some Link</a>

<script type="text/javascript">
    $(document).ready(function(){                
        $("a.buttons").history(function(event, hash) {
        $('#rightcontent').load($(this).attr('id'));    
    });
</script>

<div id="rightcontent"></div>

The hash variable always pulls in the href attribute so you need to put the link in some other attribute. I put it in the id attribute.

James Murgolo
+2  A: 

Right now, in Internet Explorer 8, Firefox 3.6+, and Chrome 5+, you can bind callbacks to the window.onhashchange event and use it without any kind of plugin.

Ben Alman has created a jQuery plugin that enables very basic bookmarkable #hash history via a cross-browser HTML5 window.onhashchange event.

http://benalman.com/projects/jquery-hashchange-plugin/

Basic usage:

$(function(){

  // Bind the event.
  $(window).hashchange( function(){
    // Alerts every time the hash changes!
    alert( location.hash );
  })

  // Trigger the event (useful on page load).
  $(window).hashchange();

});

Supported browsers:

  • Internet Explorer 6-8
  • Firefox 2-4
  • Chrome 5-6
  • Safari 3.2-5
  • Opera 9.6-10.60
  • iPhone 3.1
  • Android 1.6-2.2
  • BlackBerry 4.6-5.
aemkei
The best answer! I would give +10 if I could.
Andrey Tarantsov
A: 

jQuery History is my preferred choice. It can be found here: http://www.balupton.com/sandbox/jquery-history/demo/ Provide cross browser support, binding to hashes, overloading hashes, all the rest.

There is also a Ajax extension for it, allowing it to easily upgrade your webpage into a proper Ajax application: http://www.balupton.com/sandbox/jquery-ajaxy/demo/

This is the solution chosen by such sites as http://wbhomes.com.au/ and http://gatesonline.com.au/stage/public/

Overall it is well documented, supported and feature rich. It's also won a bounty question here http://stackoverflow.com/questions/3205900/how-to-show-ajax-requests-in-url/3276206#3276206

balupton