Sometimes, we want to capture window.onbeforeunload with JavaScript.
In this article, we’ll look at how to capture window.onbeforeunload with JavaScript.
How to capture window.onbeforeunload with JavaScript?
To capture window.onbeforeunload with JavaScript, we return a value in the method.
For instance, we write
window.onbeforeunload = () => {
return false;
};
to return false
in window.onbeforeunload
to show an alert box.
Conclusion
To capture window.onbeforeunload with JavaScript, we return a value in the method.