Trigger function by pressing F5 (refresh)

0

I am making an application in PHP that by selecting a given the combobox regarding the vessel and a date field, do a SELECT in the bank returning some data that is entered in a table.

I would like the user to select the boat (1) and by some case press the button F5 (upgrade) [2] the system calls a function.

I did a search for this functionality in JavaScript, but I did not find it.

To get more visual, follow my screen.

    
asked by anonymous 27.12.2018 / 00:52

1 answer

0

The JavaScript event that is called before reloading the page by F5 is beforeunload . I tested the code below and it worked with Jquery 3.3.1 . Note: some events such as alert are blocked in this event for security reasons.

window.addEventListener("beforeunload", function(event) {
   $.ajax({
       async: false,
       url: 'teste.php',
       data: { dados: "teste"},
       method: "POST"
   });
   return true;
});
    
27.12.2018 / 01:15