如何跟踪在Backbone.js的路由器改变事件 [英] How do I track router change events in Backbone.js

查看:119
本文介绍了如何跟踪在Backbone.js的路由器改变事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要每次运行一个函数在Backbone.js的应用程序切换的网址,我需要知道这个标签的URL已更改为。我假设有,我可以绑定到一个事件,但我一直没能找出哪些事件,并绑定到哪些对象。

I need to run a function every time the application switches URLs in Backbone.js, and I need to know the hashtag the URL has changed to. I'm assuming there is an event that I can bind to but I haven't been able to figure out which event and what object to bind to.

我特别要寄送新的URL的分析应用。

Specifically I want to ship the new URL to an analytics application.

推荐答案

@qwertymk了一半,在那里。你可以看看在窗口对象的hashchange事件:

@qwertymk was half way there. You can look for the hashchange event on the window object:

// jQuery example
$(window).bind('hashchange', function(){
    console.log(window.location.hash);
});

这篇关于如何跟踪在Backbone.js的路由器改变事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆