【发布时间】:2013-06-05 23:00:33
【问题描述】:
我正在使用 knockoutjs 和 sammyjs 处理具有多个级别的页面。
例如主页 / LEVEL1 / LEVEL2 / 当前
我已经完成了确认功能:
我怎样才能做到这一点:当人们想要离开当前页面时,将出现确认消息以确保他们确实想要离开此页面(转到 HOME、LEVEL1、LEVEL2、.. 或实际关闭选项卡,更改url) 与否。
【问题讨论】:
标签: knockout.js sammy.js
我正在使用 knockoutjs 和 sammyjs 处理具有多个级别的页面。
例如主页 / LEVEL1 / LEVEL2 / 当前
我已经完成了确认功能:
我怎样才能做到这一点:当人们想要离开当前页面时,将出现确认消息以确保他们确实想要离开此页面(转到 HOME、LEVEL1、LEVEL2、.. 或实际关闭选项卡,更改url) 与否。
【问题讨论】:
标签: knockout.js sammy.js
在var app = $.sammy(function() {...}); 内添加以下内容:
// Will run at #/route but not at #/
this.before('#/route', function() {
if(!window.confirm('Are you sure you want to leave this page?')) {
return false;
}
});
// will run at #/ but not at #/route
this.before({except: {path: '#/route'}}, function() {
if(!window.confirm('Are you sure you want to leave the home page?')) {
return false;
}
});
【讨论】: