简体   繁体   中英

Show popup message on tab close

I need to show the popup on the closing the browser tab/window. I tried the following methods but any of it does not work for me.

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

$(window).on('unload', function(){
});

Any Help will be appreciated. I am not sure if these are deprecated

Previous solution to which it is duplicated are not working

Thanks in advance

Try this one. This is working

window.addEventListener("beforeunload", function(event) {
  if (condition1) {
    event.returnValue = "\o/";
  } else {
    return;
  }
});

Update

window.addEventListener("beforeunload", function(event) {
    event.returnValue = "\o/";
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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