页面中的条件 onbeforeunload 事件

2024-01-14

window.onbeforeunload = function(evt) {
    var message = 'Are you sure you want to leave the page. All data will be lost!';

    if (typeof evt === 'undefined') {
        evt = window.event;
    }
    if (evt && !($("#a_exit").click)) {
        evt.returnValue = message;
    }
    return message;
};

我希望用户点击链接离开页面(有id ="a_exit") 仅有的。在其他情况下,例如刷新页面、点击另一个链接,系统会提示用户是否要离开该页面。我尝试使用上面的代码。当我单击退出链接时,它仍然询问我是否要离开。


$(window).bind('beforeunload',function() {
    return "'Are you sure you want to leave the page. All data will be lost!";
});

$('#a_exit').live('click',function() {
    $(window).unbind('beforeunload');
});

以上对我有用

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

页面中的条件 onbeforeunload 事件 的相关文章

随机推荐