5

I have made a flex app deep link before but now I want to make an ajax app deep link.

I have no idea where to start.

I assume I need a way to listen for when the #hash in the url changes and be able to read it. And I assume I need a way to update the #hash in the url.

Does anyone know how to do all that?

Thanks!

JD Isaacks
  • 56,088
  • 93
  • 276
  • 422

3 Answers3

6

You're on the right track.

For each state of the ajax page that you want to be able to link to, change the hash tag:

window.location.hash = "this_state"

When the page loads you'll need to check if the window.location.hash value matches one of your states and if it does make the app go to that state. ("Listening" for the change of the hash tag is the page loading.)

This way your users can bookmark and share the states, making for a much more usable app, so props for caring about it.

edeverett
  • 8,012
  • 33
  • 28
  • What you said works somewhat but when I hit the back button the hash changes but the page doesn't reload so my script is unaware. I think this requires some way of listening for the hash to change. – JD Isaacks May 26 '09 at 13:43
  • Yeah, you're right! It works fine in FF for my example, but differently in IE and Webkit. What would add force a page to refresh? Possibly by adding to the window.history object at every state change - adding a different query string as well as the hash might do it. Otherwise I suppose you could poll the window.location every so often: There isn't a onhashchange event as far as I know. – edeverett May 27 '09 at 14:56
  • There's a jquery plugin (http://plugins.jquery.com/project/history) for managing the window history – BC. Oct 02 '09 at 17:46
2

have a look at SWFAddress (deep linking for both Flash and Ajax)

UPDATE: if you use jQuery look at their jQuery Address

Gideon
  • 18,251
  • 5
  • 45
  • 64
0

If you're using jquery you might want to have a look at this:

Deep Linking with jQuery Address plugin

gomezuk
  • 299
  • 6
  • 15