页面中的条件onbeforeunload事件 [英] Conditional onbeforeunload event in a page

查看:123
本文介绍了页面中的条件onbeforeunload事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)。在其他情况下,例如刷新页面,单击另一个链接,将提示用户他/她是否要离开页面。我试过使用上面的代码。当我点击退出链接时,它仍然会询问我是否要离开。

I want user to leave the page clicking to the link (has id ="a_exit") only. In other circumstances such as refreshing the page, clicking another link, user will be prompted that if he/she wants to leave the page. I have tried to use the code above. It still asks me if I want to go away when I click the exit link.

推荐答案

你可以删除<$ c $单击处理程序中的c> window.onbeforeunload 。

这篇关于页面中的条件onbeforeunload事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆