我有一段代码,这段代码在 Backbone 应用程序中更改路由时执行:
mediaMatchUnRegister: function () {
if (this.mediaMatchState.registered) {
enquire.unregister(this.mediaMatchState.tabletAndUpQuery)
.unregister(this.mediaMatchState.mobileQuery);
this.mediaMatchState.registered = false;
}
}
这一切都运行得很好,除了以下条件:
- 应用程序正在 Chrome 中运行
- 我点击了该页面上的“打印”按钮,这会打开 Chrome 打印预览对话框。
如果我没有调出 Chrome 打印预览对话框,那么它运行得很好。FF 和 IE,没有这个对话框,对此没有任何问题。
问题在于enquire.js
,特别是在clear()
方法中:
clear : function() {
each(this.handlers, function(handler) {
handler.destroy();
});
this.mql.removeListener(this.listener);
this.handlers.length = 0; //clear array
},
如果我没有触发打印预览对话框this.mql
是MediaQueryList
. 如果我触发了它,那么this.mql
现在是MediaQueryListEvent
. 然后它失败了,因为这个对象似乎没有 removeListener 方法。
有人遇到过这种情况么?Chrome 打印预览对话框是红鲱鱼吗?