Javascript 在 JQuery 中执行 URL 哈希/历史记录的最佳库是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2358928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the best library to do a URL hash/history in JQuery?
提问by TIMEX
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.
我一直在寻找 URL 哈希的 JQuery 库,但没有找到好的。有“历史插件”,但我们都知道它有问题并且不灵活。
I am loading my pages inside a div. I'll need a way to do back/forward along with the url hashing.
我正在一个 div 中加载我的页面。我需要一种方法来进行后退/前进以及 url 散列。
mydomain.com/#home
mydomain.com/#aboutus
mydomain.com/#register
What's the best library that can handle all of this?
可以处理所有这些的最好的库是什么?
回答by Matt Frear
I recently looked at 3 different plugins - jquery history plugin, history, and jQuery BBQ.
我最近查看了 3 个不同的插件 - jquery history plugin、history和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).
它们都很难设置,我确实让 jQuery.history 工作,但它仍然有 IE7 的问题。所以我改用 BBQ,它在我们所有的目标浏览器(IE6、IE7、IE8、Fx3)上都运行良好。
So I recommend the jQuery BBQ plugin.
所以我推荐jQuery BBQ插件。
Edit: here's a blog postI just wrote which demonstrates jQuery BBQ with cascading dropdowns.
回答by Batailley
Have you tried jQuery Address? From Asual, the guys who made SWFAdress. Asual - jquery Address
你试过 jQuery 地址吗?来自 Asual,制作 SWFAdress 的人。Asual-jquery地址
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.
jQuery Address 插件提供强大的深度链接功能,并允许创建可以指向网站部分或应用程序状态的唯一虚拟地址。
回答by Justin
History.jsis well documented/maintained and supports all browsers.
History.js文档齐全/维护良好,支持所有浏览器。
https://github.com/browserstate/history.js
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.
History.js 优雅地支持所有浏览器中的 HTML5 历史/状态 API(pushState、replaceState、onPopState)。包括对数据、标题、replaceState 的持续支持。支持 jQuery、MooTools 和 Prototype。对于 HTML5 浏览器,这意味着您可以直接修改 URL,而不再需要使用哈希。对于 HTML4 浏览器,它将恢复使用旧的 onhashchange 功能。
回答by kevingessner
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.
我在真正简单的历史(nee dhtmlHistory)方面很幸运。它不是特定于 jQuery 的,但它适用于 IE、firefox 和 webkit,并且不需要太多设置。
回答by balupton
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.
也许试试这个 jQuery History 插件:https: //github.com/balupton/jquery-history/它提供跨浏览器支持、绑定到散列、重载散列等等。
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/
它还有一个 Ajax 扩展,允许它轻松地将您的网页升级为合适的 Ajax 应用程序: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?
总的来说,它有很好的文档记录、支持和丰富的功能。它还在这里赢得了一个悬赏问题如何在 URL 中显示 Ajax 请求?
Or if you want to use the HTML5 History API there is: https://github.com/browserstate/history.js
或者,如果您想使用 HTML5 History API,请访问:https: //github.com/browserstate/history.js
回答by noah
AFAIK, all history plugins do the same thing:
AFAIK,所有历史插件都做同样的事情:
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.
这就是它的核心(减去无需单击链接即可添加历史条目的浏览器技巧等)。它总是会出问题,因为它有点hack,并且没有用于处理历史更改的跨浏览器API。
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.
最重要的是,这种事情的用户体验不是很好。用户不明白什么时候他们必须点击 4 次后退按钮才能离开页面。

