I have a form that needs to be submitted on all button presses or whenever a user leaves the page, is that possible if so how?
Asked
Active
Viewed 34 times
0
-
"a form that needs to be submitted ... whenever a user leaves the page" - that is just incredibly bad design and user experience, why do you need this? – kalatabe Sep 29 '16 at 08:45
-
1I would rather implement AJAX to do this. Then you can - maybe - show a "Closing application.." or something when user leaves page. You can do this by binding an AJAX call to the 'onunload' Javascript event. – Jan Willem Sep 29 '16 at 09:17
-
1Also see: http://stackoverflow.com/questions/14929832/send-ajax-to-server-beforeunload – Jan Willem Sep 29 '16 at 09:30
1 Answers
0
Using jquery to detect if a user leaves the page. https://api.jquery.com/unload/
$( window ).unload(function() {
//call your function here that executes the form
return "Handler for .unload() called.";
});
using jquery to detect button presses.
$(document).on('click', '.buttonCLass', function(){
//code here
})

Wim Pruiksma
- 588
- 5
- 19