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

谁说我不能喝 提交于 2019-12-17 10:37:18

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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.



来源:https://stackoverflow.com/questions/2358928/whats-the-best-library-to-do-a-url-hash-history-in-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!