2

I have a user progress data stored in the form that I submit at regular intervals or on certain sequence or exit button of app.

The issue I am facing is if the user navigates through the app and then closes the browser window directly (instead of clicking the exit button in the app), the user progress data is lost as the form submit does not work and the browser window closes before that.

I have tried the following and it works fine in Chrome:

function listenForUnloadEvent()
{
    $(window).on('beforeunload', function ()
    {
       ... trackBeforeExitCourse();
    }
}

function prepareForm() {
    .....
    $(window).bind('beforeunload', function () {
        myForm.submit();
    });
}

however, the above code does not work on Safari or Firefox.

The client does not want to show any warning message on trying to close the window, instead they want us to submit the form and store the user progress data.

Any help would be appreciated.

Manmeet Bhurjee
  • 143
  • 1
  • 10

1 Answers1

0

try like below.You can refer this MDN document for more information.

$(window).on('beforeunload', function(e) { 
   $('form').submit();
});
Ketan Modi
  • 1,780
  • 1
  • 16
  • 28