简体   繁体   English

Javascript / HTML关闭窗口事件

[英]Javascript/Html Close Window Event

I am trying to do this in html and js but not refresh or reload just trigger when its getting closed. 我试图在html和js中执行此操作,但不刷新或重新加载只是在关闭时触发。 I used functions like onbeforeunload,unload but they didnt work. 我使用了诸如onbeforeunload,unload之类的函数,但它们没有起作用。
sample image 样本图片

Try This with jQuery: 尝试使用jQuery:

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

Or with javascript 或使用javascript

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM