Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Is there a similar event to onbeforeunload? #146

Closed
nearapogee opened this issue Jul 22, 2016 · 4 comments
Closed

Is there a similar event to onbeforeunload? #146

nearapogee opened this issue Jul 22, 2016 · 4 comments

Comments

@nearapogee
Copy link

Is there a similar event to onbeforeunload?

Looking for a way to attach onto an event when transitioning off of a page with or without a turbolinks link. Is that possible?

Thanks!

@sstephenson
Copy link
Contributor

Listen for turbolinks:before-render to be notified just before Turbolinks replaces the <body> element.

You can combine this with window.onbeforeunload to create an unofficial turbolinks:unload event:

var dispatchUnloadEvent = function() {
  var event = document.createEvent("Events")
  event.initEvent("turbolinks:unload", true, false)
  document.dispatchEvent(event)
}

addEventListener("beforeunload", dispatchUnloadEvent)
addEventListener("turbolinks:before-render", dispatchUnloadEvent)

@sergiy17
Copy link

@masudhossain
Copy link

@nearapogee https://github.com/turbolinks/turbolinks#full-list-of-events

And which one is suppose to fix this issue?

@nearapogee
Copy link
Author

That was 5 years ago... but I think @sstephenson fix worked for me. Basically create a meta event that is triggered both by the browser and turbolinks. Make sense?

By the way, thanks @sstephenson I am just a few years late in saying that!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants