views:

1528

answers:

6

What is the best tool / practice to enable browser history for Flash (or AJAX) websites? I guess the established practice is to set and read a hash-addition to the URL like

http://example.com/#id=1

I am aware of the Flex History Manager, but was wondering if there are any good alternatives to consider. Would also be interested in a general AJAX solution or best practice.

+2  A: 

For AJAX, something like Really Simple History is great.

EndangeredMassa
+2  A: 

I've used swfadress for some small stuff.

grapefrukt
A: 

This will seem a bit roundabout, but I'm currently using the dojo framework for that. There's a dojo.back that was very useful when my UI was mostly JS/HTML. Now that I've gone to flex for more power, fluid animations, and browser stability, the only thing I've need to keep using has been the back URL.

FlexBuilder seemed to have it's own browser history in default projects.

Also, the Flex 3 Cookbook has a recipe for using mx.managers.HistoryManager to create your own custom history management. I have plans to give this a try someday to remove our dependence on the dojo.back, but haven't had time yet.

Glenn
+4  A: 

SWFAddress has been widely used and tested. It makes it almost trivial (given you plan ahead) to handle deeplinking in Flash. It provides a JS and AS library that work together and make the whole process pretty foolproof. You'd want to look at something like RSH for AJAX.

RickDT
A: 
    -


  1. ![List item][1]


A: 

I've rolled my own solutions that were ultra-simple like this:

(function() {
  var oldHash, newHash;

  function checkHash() {
    // Grab the hash
    newHash = document.location.hash;

    // Check to see if it changed
    if (oldHash != newHash) {

      // Trigger a custom event if it changed,
      // passing the old and new values as
      // metadata on the event.
      $(document).trigger('hash.changed', {
        old: oldHash,
        new: newHash
      });

      // Update the oldHash for the next check
      oldHash = newHash;
    }
  }

  // Poll the hash every 10 milliseconds.
  // You might need to alter this time based
  // on performance
  window.setInterval(checkHash, 10);

})(jQuery);

Then you just need to have event handlers for the 'hash.changed' event to respond accordingly based on what the new value is. The approach works will in super simple cases.

nakajima
interesting. Can you post a demo somewhere?
pixeline