What's the best library to do a URL hash/history in JQuery? [closed]
Asked Answered
I

6

23

I've been looking around JQuery libraries for the URL hash, but found none that were good. There is the "history plugin", but we all know it's buggy and isn't flexible.

I am loading my pages inside a div. I'll need a way to do back/forward along with the url hashing.

mydomain.com/#home
mydomain.com/#aboutus
mydomain.com/#register

What's the best library that can handle all of this?

Issue answered 1/3, 2010 at 20:39 Comment(0)
M
25

I recently looked at 3 different plugins - jquery history plugin, history, and jQuery BBQ.

They were all quite hard to setup, I did get jQuery.history working but it still had problems with IE7. So I changed to BBQ and it worked fine across all our target browsers (IE6, IE7, IE8, Fx3).

So I recommend the jQuery BBQ plugin.

Edit: here's a blog post I just wrote which demonstrates jQuery BBQ with cascading dropdowns.

Molybdenous answered 1/3, 2010 at 22:39 Comment(0)
F
1

Have you tried jQuery Address? From Asual, the guys who made SWFAdress. Asual - jquery Address

The jQuery Address plugin provides powerful deep linking capabilities and allows the creation of unique virtual addresses that can point to a website section or an application state.

Foulup answered 16/10, 2010 at 23:53 Comment(1)
I tried this plugin and it had issues with when the change event was registered.Fester
P
1

History.js is well documented/maintained and supports all browsers.

https://github.com/browserstate/history.js

From the site:

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

Prim answered 10/4, 2014 at 21:35 Comment(0)
F
0

I've had good luck with reallysimplehistory (nee dhtmlHistory). It's not jQuery specific, but it works in IE, firefox, and webkit, and doesn't require much setup.

Fluoridation answered 1/3, 2010 at 22:50 Comment(1)
This software seems to be from 2009 and the latest Google Group post is in 2013. The code is not easily available now, either.Florist
T
0

Perhaps try this jQuery History plugin: https://github.com/balupton/jquery-history/ It provides 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: https://github.com/balupton/jquery-ajaxy/

Overall it is well documented, supported and feature rich. It's also won a bounty question here How to show Ajax requests in URL?

Or if you want to use the HTML5 History API there is: https://github.com/browserstate/history.js

Talaria answered 27/7, 2010 at 10:30 Comment(1)
First link appears to be dead due to security issue.Florist
K
-4

AFAIK, all history plugins do the same thing:

setInterval(function() {
   if(theHashChanged) {
      someFunction(oldHash,newHash);
   }
}, 500/*whatever*/);

That's pretty the core of it (minus browser hacks for adding history entries without clicking a link, etc.). It's always going to be buggy because it's a bit of a hack and there is no cross browser API for handling history changes.

On top of all that, the user experience for this sort of thing is not very good. Users don't understand when they have to click the back button 4 times to get off the page.

Kenner answered 1/3, 2010 at 21:6 Comment(6)
-1: Not at all helpful. And since when do users expect that the back-button takes them off the page? Do you only surf flash-sites?Foul
@Foul it's based on my experience with a large, public facing site. Just because you can implement something like this, doesn't mean you should. I honestly can't think of a single site where this feature is more helpful than annoying.Kenner
@Foul - "since when do users expect that the back-button takes them off the page?" Since the web and web browsers where first introduced, I would say ;). The normal function of the back-button is of course to go from the current page to the previous page.Apochromatic
@Lars: Yes. So if I'm e.g. browing amazon and first visit one book and then another I expect that the back-button takes me back to the first one, not off the amazon website. How amazon implements their page (using the hash or whatever) shouldn't matter at all. That is the whole point of the question.Foul
@noah: Maybe you should "educate" your employer about their mistake: If I click on the back-button on optaros.com that brings me back to the prebious visited subpage on their website, it doesn't take me off their site.Foul
@Foul Now you're just trolling. Who said anything about the back button taking them off the site? The back button goes back to the last page. The user can tell the difference between an Ajax load and a new page (if they can't, why bother with the Ajax?) and does not typically expect an Ajax load to result in a history entry.Kenner

© 2022 - 2024 — McMap. All rights reserved.