vue-use-kit icon indicating copy to clipboard operation
vue-use-kit copied to clipboard

useBeforeUnload - not preventing unload

Open chrisspiegl opened this issue 2 years ago • 0 comments

It looks like the e.preventDefault() is not enough in some browsers (Brave is where I tested).

However, if I also do e.returnValue = '', it does prevent and ask if I really want to close the tab.

This would be an easy fix:

https://github.com/microcipcip/vue-use-kit/blob/584bc1a3a050fcb82fc8cc3d825c3b8611edbbb0/src/functions/useBeforeUnload/useBeforeUnload.ts#L6-L9

const handleBeforeUnload = (e: BeforeUnloadEvent) => {
    // Show alert message only when isPageDirty is true
    if (isPageDirty.value) {
        e.preventDefault()
        e.returnValue = '';
    }
  }

Source: https://community.plumsail.com/t/any-way-to-prevent-user-from-closing-tab-or-showing-a-warning-before-they-close-it-from-within-forms/10261/8

chrisspiegl avatar Apr 11 '23 10:04 chrisspiegl