Are there any javascript libraries for working with hashbang/shebang (#!) urls?

淺唱寂寞╮ 提交于 2019-12-20 10:44:21

问题


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?


回答1:


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




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/5021365/are-there-any-javascript-libraries-for-working-with-hashbang-shebang-urls

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