c# - 如何在浏览器中生成 'Are you sure you want to navigate away from this page' 警告消息?

标签 c# javascript asp.net

我有一个包含文本框和提交按钮的网页。当用户编辑文本框中的文本并单击另一个链接(不是提交按钮)时,我如何显示“您确定要离开此页面”弹出消息吗?

我在网上对此进行了研究,并找到了一些 javascript 示例。这是你能做到这一点的唯一方法吗?如果不是,最好的方法是什么?

最佳答案

这是实现同一件事的多种方法之一

function goodbye(e) {
    if(!e) e = window.event;
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog

    //e.stopPropagation works in Firefox.
    if (e.stopPropagation) {
        e.stopPropagation();
        e.preventDefault();
    }
}
window.onbeforeunload=goodbye;

从这里得到 open js

关于c# - 如何在浏览器中生成 'Are you sure you want to navigate away from this page' 警告消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9395515/

相关文章:

PHP,加载时提交表单

c# - 通过枚举或关系表定义数据状态

c# - 为什么 ASP.NET 网站没有 designer.cs?

javascript - 根据条件删除未选择的文件

c# - 在 C# 中设置 for 循环迭代次数的限制

c# - 正确设置 MdiParent 背景图片

javascript - 使用 while 循环创建 cron 作业

c# - 使用 C# 将文件/文件夹添加到 Program Files x86 文件夹

c# - C# 根据键对字典列表进行排序

javascript - 刷新应用于元素属性的 css