Question

Is there a way to fake an onwindowunload event with Turbolinks?

Essentially, I am looking for a way to cancel a page:fetch event, but couldn't figure how.

Was it helpful?

Solution

There is now a mechanism in TurboLinks to cancel a page change.

Here's a lib I made that abstracts the fact that your user may or may not be using TurboLinks : https://gist.github.com/jbourassa/6529382

This code also allows you to simply have multiple handlers for unloading.

And I use it like that:

Unloader.register(function() {
    return "Please don't go!!";
});

This will automatically be removed on the next successful page change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top