Question

I'm trying to attach a listener for onbeforeunload in my app but it doesn't seem to be caught by enyo.Signals.

According to the Documentation:

Within the Enyo framework itself, DOM events that have no node targets are broadcast as signals. These events include window events, like onload and onbeforeunload, and events that occur directly on document, like onkeypress if document has the focus. Signals are also useful for hooking up non-Enyo events (e.g., PhoneGap events) to be handled by Enyo kinds in application code.

I wrote the following test case:

 enyo.kind({
    name: "App",
    kind: "enyo.Control",
    fit: true,
    content: "Hello World",

    components:[
        {kind: "enyo.Signals", onbeforeunload: "test"}
    ],

    test: function(inSender, inEvent) {
         return 'You have unsaved changes!';
    }
});

This seems to have no effect when I close the tab or navigate away from the page. What am I missing? Here is the JSFiddle

Was it helpful?

Solution

It doesn't look like we are handling beforeunload by default:

https://github.com/enyojs/enyo/blob/master/source/dom/dispatcher.js

But, you can get it to work with something like

enyo.dispatcher.listen(window, "beforeunload");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top