Skip to content
API for window.beforeunload that also works with Turbolinks 2.
CoffeeScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
README.md
bower.json
index.coffee
index.js

README.md

beforeunload.js

API

BeforeUnload.enable(
  # Only gets triggered if this returns truthy
  if: -> inputHasChanged

  # The warning message that is displayed
  message: "You have entered data that is not yet saved."

  # If triggered by Turbolinks, call this function instead
  # of displaying the warning message. Returning `false` from
  # this function will still show the BeforeUnload alert.
  cb: (url) ->
    saveInput -> Turbolinks.visit(url)
)

BeforeUnload.disable()

License

MIT

Something went wrong with that request. Please try again.