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

后端 未结 4 1116
独厮守ぢ
独厮守ぢ 2021-02-04 06:28

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\'

4条回答
  •  佛祖请我去吃肉
    2021-02-04 07:08

    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.

提交回复
热议问题