I need to save the data of the current web page to the database if the user leaves this. How can I achieve this? I'm using Ruby on Rails for the backend.
Asked
Active
Viewed 66 times
0
-
1There is no event handler for when the user leaves the page. See here : http://stackoverflow.com/questions/11026152/how-to-detect-if-a-user-leaves-a-page-in-php – Andrew Magill Jun 22 '16 at 20:56
-
This seems like something that your analytics service should handle. As AyexeM mentioned, I don't think there is a way to do it with rails. – ruby_newbie Jun 22 '16 at 21:26
1 Answers
0
This is tricky.
What I would do is save each field on the blur event something like this
$("input").blur(function(){
$("form.form_class").submit();
});
I am thinking that you would have to just update where the form submits to so you dont create a new record on when you are on the new page.
you can see an example of blur here

MZaragoza
- 10,108
- 9
- 71
- 116