Alternatives to beforeunload event listener in FF

1

I'm working on a website and JavaScript has an important role on the front end, I was using the beforeunload event to always check if the user has edited anything on the page to warn you of possible information loss.

It turns out that this event is not compatible with firefox. What alternative can I use to do this verification?

    
asked by anonymous 26.01.2017 / 12:03

1 answer

1

onbeforeunload should work .

Code example - compatible with IE > = 7 also

var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload';

myEvent(chkevent, function(e) {
    fazerAlgumaCoisa();
});

Solution tested in Firefox Nightly 53.0a1

    
26.01.2017 / 12:34