How to prevent a webpage from closing

Categories:

I needed to prevent a webpage from closing automatically. Turns out this is very easy to do with JavaScript!

Just paste this one-liner into the JavaScript console.

window.onbeforeunload = function(){alert();}