0

我正在使用 knockoutjs 和 sammyjs 处理具有多个级别的页面。
eg HOME / LEVEL1 / LEVEL2 / CURRENT 我已经完成了确认功能:

我怎样才能做到这一点:当人们想要离开当前页面时,会出现确认消息以确保他们确实想要离开此页面(转到 HOME、LEVEL1、LEVEL2、.. 或实际关闭选项卡,更改网址)与否。

4

1 回答 1

0

在里面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;
    }
});

来源:Sammy.Application before (options, callback)

于 2013-06-06T17:55:05.560 回答