Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto save/submit form on page/browser close/exit

Tags:

javascript

php

I have a form with a save button, but i want users to be able to come back to the form at anytime to finish filling it in. I would like to know if its possible to bypass the save button, so the user fills part of the form in, as soon as they navigate away from the page or close their browser it will save the form automatically to resume next time.

What would be the best way to implement this? Thanks in advance for any help, its much appreciated.

I have seen some javascript examples but have seen issues with cross browser support.

like image 827
Codded Avatar asked Nov 04 '22 16:11

Codded


1 Answers

You can use an AJAX Call on unload like this:

window.onunload = myfunc();

function myfunc() {
  alert("i am closing now");
  // Your AJAX Call that saves your data (e.g. all input fields)
}
like image 60
scube Avatar answered Nov 11 '22 16:11

scube