Javascript/Html 关闭窗口事件

标签 javascript jquery html

我试图在 html 和 js 中执行此操作,但不刷新或重新加载,只是在关闭时触发。我使用了 onbeforeunload、unload 等函数,但它们不起作用。
sample image

最佳答案

用 jQuery 试试这个:

$(window).bind('beforeunload', function(){
  return 'Are you sure you want to leave?';
});

或者使用 JavaScript

window.onbeforeunload = function(){
  return 'Are you sure you want to leave?';
};

关于Javascript/Html 关闭窗口事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39270546/

相关文章:

java - GWT 2.6 的用户代理?

javascript - 将光标设置到文本区域中特定行的特定位置

php - jquery AJAX 发送和接收数据请求中的未定义索引

javascript - 如何使用 jquery 将 html 加载到变量中

javascript - 获取包含特定值的 <li> 标签的 id

javascript - IE8/IE7/IE6 似乎将通过 JQuery 插入的 anchor 标记视为 block 级元素

Javascript/jQuery 滚动顶部问题

jquery - 为 HTML 表格中的数据创建相对颜色算法的最佳方法是什么?

java - 找到 MIME 类型并且没有支持格式的视频

javascript - 如何将参数从一个html页面传递到另一个