Categories
JavaScript Answers

How to capture window.onbeforeunload with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.