0

I want to send an ajax request only when the browser window closes not on refresh or reload. I am using this code.

DisplayExit = function() {  
     simpleAjaxReq("formatter_main.php",'file_close' , 'true');  
};
window.onbeforeunload = DisplayExit;

This works when closing the browser window but also execute the code when the page reloads, is there a way for this code to only works on close not reload.

  • How is this answered, the question you are directing me towards is also using the same function which also fire when i refresh the browser i wanted to limit it to only when the browser window is closed. – Siyad Nijah Jan 22 '19 at 02:18

1 Answers1

0

You need a function onload as well to disable it similar to below sample

     window.onload(function()
       {
     response.sendRedirect(url);
        // or     
         simpleAjaxReq("formatter_main.php",'file_close' , 
          'false');
         }
Himanshu
  • 3,830
  • 2
  • 10
  • 29