Html5History触发两次导航事件
Google Closure - Html5History fires NAVIGATE event twice
为什么google .history。Html5History对象火灾google .history. eventtype . navigate事件两次每次片段被改变?下面是代码示例:
var history = goog.history.Html5History.isSupported()
? new goog.history.Html5History()
: new goog.History();
goog.events.listen(history, goog.history.EventType.NAVIGATE, function(e) {
console.log(['navigation', e.target.getToken()]);
});
history.setEnabled(true);
这是log:
["navigation", "!/properties/new"]
["navigation", "!/properties/new"]
UPD:我发现在回调中e
对象的isNavigation
字段有两个不同的值。第一次取false
值,第二次取true
值。isNavigation
意味着:
isNavigation如果事件是由浏览器操作触发的,则为True如向前或向后,点击链接,编辑URL或调用window.history。(去| |转发)。如果令牌已更改,则为False通过setToken或replaceToken调用。
但是怎样才能只解雇一个人呢?
我遇到了同样的问题。但在我的情况下,这两个事件都有isNavigation==true
。
init = function() {
var h = goog.history.Html5History.isSupported() ?
new goog.history.Html5History() : new goog.History();
goog.events.listen(h, goog.history.EventType.NAVIGATE, navigationCallback);
h.setEnabled(true);
};
navigationCallback = function(e) {
console.log(e, e.token, e.isNavigation);
};
// And then:
h.setToken("example1");
h.setToken("example2");
// And click "back" button in browser
输出:goog.history.Event "example1" false
goog.history.Event "example2" false
goog.history.Event "example1" true
goog.history.Event "example1" true
我有一些问题…
做谷歌解雇一次http://closure-library.googlecode.com/git/closure/goog/demos/history1.html
init可能会发生两次?
相关文章:
- Meteor Router数据函数被调用两次
- 从MySQL数据库中获取输入数据需要两次页面刷新
- Module.start()已激发两次
- Jquery点击事件必须点击两次
- Append元素在运行两次函数后不显示
- 防止双击执行两次jQuery post请求
- 我必须点击两次才能激活任何按钮操作(离子/角度)
- 单击jQuery会激发两次
- 如何避免在树上走两次
- button.单击两次删除附加操作后不工作
- 由于$compile,Javascript(Angular)嵌套指令加载了两次
- 单击元素两次后执行操作
- AngularJs正在阻止链接被点击两次
- 为什么我的路线处理程序会触发两次
- 为什么Highchart在我的rails应用程序中加载了两次?(未捕获的Highcharts错误#16)
- 在列表中至少使用两次随机生成的nr
- 为什么同一个视图在Durandal日志中导航了两次
- Html5History触发两次导航事件
- 在AngularJS和Ionic中,每次状态转换都会发生两次导航
- 控制器内部的离子导航按钮触发两次