locked
Function Not Executing On Page Unload RRS feed

  • Question

  • User-1231523685 posted

    I'm using the OnBeforeUnload method to detect page reload and when it is detected it will show a popup message and the options to either cancel or Leave the page. If the user decides to leave the page then the unload method is called and in side of the unload I'm trying to call a bunch of methods to clear my jqGrid and do many other things.

    Below is what I have tried but it's not working:

    function ClearData(){
       // perform task1
       // perform task2
       // perform task3
       .
       .
    }
    
    $(document).ready(function(){
            $(window).on("unload", function () {
                 ClearData();
            });
    
            $(window).on('beforeunload', function () {
                 return "If you reload this page you will lose data!"
            });
    });
    

    Thursday, June 28, 2018 5:58 PM