Javascript: Programmatically Trigger Onbeforeunload/onunload Event
How can I programmatically trigger onbeforeunload and onunload events?(No jquery please). I've tried:
Solution 1:
window.dispatchEvent(newEvent('beforeunload'))
I think this would be the best way in 2020. In case anyone finds this.
window.addEventListener('beforeunload',()=>{console.log("beforeunload triggered")})
window.dispatchEvent(newEvent('beforeunload'))
Post a Comment for "Javascript: Programmatically Trigger Onbeforeunload/onunload Event"