jeudi 13 avril 2017

Ember js run function when user closes window

I have an ember application where users are stored in a MySQL database. When a user exits (ie. closes their browser window), they need to be deleted from the database. I have the following code in one of my route files:

  setupController: function () {
    $(window).on('beforeunload', () => {
    this.get('currentUser').delete();
    });
  },

In my testing this only seems to delete the user from the database maybe 70-80% of the time, and somehow it seems to be random whether it works or not. I'm guessing this is because sometimes the function isn't run in time before the browser has closed the window. How can I ensure the code to delete a user is executed every time a user exits?




Aucun commentaire:

Enregistrer un commentaire