This is such a valuable UX pattern! I've implemented similar functionality and the user feedback is always positive. The beforeunload event handling you've shown is spot on. Pro tip: consider also implementing a draft auto-save mechanism alongside this to give users extra peace of mind. The combination of unsaved change alerts + auto-drafts creates a really robust content preservation system.