Alternatives to beforeunload Event Switch in FF

Asked

Viewed 71 times

1

I’m working on a website and Javascript has an important role in front-end, I was using the event beforeunload to always make a check if the user edited something on the page, to warn you about possible loss of information.

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

1 answer

1


The onbeforeunload should work.

Code example - IE >= 7 compliant too

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

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

Solution tested in Firefox Nightly 53.0a1

  • 1

    It works very well! I was already getting desperate because I thought I could not do what I wanted, but I was wrong. Thank you

  • Nice to be able to help =D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.