Avoiding Safari exit confirmation dialog for dirty forms

Safari asks close confirmation if a form field isn't clean

Safari asks for your confirmation if you accidentally try to close a page if you filled a form but never submitted. This saved my day more than once and it’s undoubtedly helpful.

The problem is that if you’re sending the form via ajax Safari still thinks you’re loosing some data. Luckily the fix is easy:

var postBody = document.querySelector('textarea.post-body')
postBody.defaultValue = postBody.value

Leave a Reply

Please Login to comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.