javascript - How to monitor browser refresh, close, and back behavior on PC?
为情所困
为情所困 2017-07-05 10:56:28
0
1
1101

How to monitor the browser refresh, close, and back behavior on PC? Then pop up the custom layer?
I tried onbeforeunload method. No alert pops up.

为情所困
为情所困

reply all(1)
仅有的幸福

unload cannot preventDefault, the reason is obvious when you think about it, to prevent users from being unable to close the webpage

This is what you should do:

onbeforeunload = function (){
  if (unsaved) return '本次编辑未保存, 确认关闭网页?'
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template