Is the onbeforeunload event running now?
When you close the browser, you need to display an alert in which the text stating that there is unsaved data on the page ...
return "что угодно, браузер скорее всего напишет свое сообщение";
To place the code, please use CodePen or similar tool. Thanks you!