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.
仅有的幸福2017-07-05 10:58:28
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 '本次编辑未保存, 确认关闭网页?'
}