Many ways to deal with events in javascript
Callbacks vs. custom events in vanilla JS | Go Make Things
DOMContentLoaded vs jQuery.ready vs onload, How To Decide When Your Code Should Run - Eager Blog
Sure you want to leave?—browser beforeunload event
How to prevent browser refresh, URL changes, or route navigation in Vue