15

With all the negative press over Twitter and Gawker's use of hashbang urls I'm having a very hard time finding any examples/libraries for how to actually use them.

I'd like to use hashbang urls in a javascript carousel on our website so we can link directly to a specific page of the carousel.

Are there any good cross-browser libraries or examples (preferably non-jQuery, since we use Prototype) for both pushing new urls to the page location and for parsing the url on page load?

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Twipped
  • 1,149
  • 12
  • 24
  • 1
    Negative Press? Seems [perfectly acceptable](http://code.google.com/web/ajaxcrawling/docs/specification.html) to me. – Brad Christie Feb 16 '11 at 19:52
  • Yeah.. what negative press are you referring to? – drudge Feb 16 '11 at 20:15
  • 1
    Here's one : "Breaking the web with Hash Bangs" http://isolani.co.uk/blog/javascript/BreakingTheWebWithHashBangs What I like particularly is when the author talks about how HashBangs and overreliance on the correctness of JavaScript not written by the site authors have, in the new world of HTML managed to break websites in all the ways that people who feared XHTML said that XHTML would. – scriptocalypse Feb 16 '11 at 20:36
  • Just try doing a google search for 'javascript hashbang', the first three pages are mostly articles about gawker's new roll out. The rest are just explaining what a hashbang is and how to use it in SEO. – Twipped Feb 16 '11 at 20:44
  • 1
    There has been negative press. Tim Bray weighed in recently: http://www.tbray.org/ongoing/When/201x/2011/02/09/Hash-Blecch – Tim Down Feb 17 '11 at 00:02
  • Also http://simonwillison.net/tags/hashbanghell/ – Tim Down Feb 17 '11 at 09:50

4 Answers4

6

We've been working on a library that does URL route mapping: https://github.com/OpenGamma/RouteMap if you're still looking for one.

afshin
  • 204
  • 1
  • 4
  • So, if I read this correctly, you add url patterns to the lib, and when the hash changes to match one of the patterns it triggers an associated function? – Twipped Mar 31 '11 at 18:26
  • Yes, that's right. I have updated the documentation to make that a little more clear. Sorry for the late response. – afshin Apr 05 '11 at 14:37
  • This is more-or-less what I was looking for. Thank you! – Twipped Apr 13 '11 at 17:42
1

Sammy.js uses them to create handlers like the ones used in Sinatra.

ebaxt
  • 8,287
  • 1
  • 34
  • 36
0

Google Closure Library has a really cool implementation for browser history stack. You can reach history source code from here.

To use Closure Library history manager you should define a hidden input. There is the trick. If you don't give a input field to class, it will create one for you, but it will try to append it DOM with document.write because of cross browser support. The best and easy way is providing a hidden input.

Here is a simple implementation of goog.History.

var history = new goog.History(false, '', document.getElementById('historyInput'));
goog.events.listen(history, goog.history.EventType.NAVIGATE, function() {
    console.log(history.getToken());
});
history.setEnabled(true);

Then navigate to some hashed urls in your page and you should see your changed hash in your console as log.

Fatih Acet
  • 28,690
  • 9
  • 51
  • 58
0

https://github.com/browserstate/History.js I have no experience with it as I use BBQ Jquery, but it looks like it should solve your problems.

balupton
  • 47,113
  • 32
  • 131
  • 182
Logan Bailey
  • 7,039
  • 7
  • 36
  • 44
  • This comes really close, but it's producing completely different urls in different browsers. I need it to be consistent. – Twipped Feb 16 '11 at 20:46