javascript - Is it possible to save all field information when the user closes his browser? -


e.g. writing article accidently closes browser. possible save wrote?

something this:

onexit -> information user filled -> ajax request saves information in database.

or

is possible preemptively saving every x second?

my company running ajax query save every 5 seconds, should localstorage saving on client, use onunload save , recover later.

i made html5 notepad stores localstorage every onchange event , every 500ms , onbeforeunload save 1 field, easy modify, here's (essential) code:

<textarea placeholder="type here, see here..."  id="notepad"></textarea> <script>     var n = document.getelementbyid("notepad");     /* save */     var s = function(){localstorage.setitem("notepad", n.value);}     /* retrieve (only on page load) */     if(window.localstorage){ n.value = localstorage.getitem("notepad");}     /* autosave onchange , every 500ms , when close window */     n.onchange = s();     setinterval( s, 500);     window.onunload = s(); </script> 

if view source on that page, you'll find polyfill used support older browsers, localstorage should work in ie8+

i wouldn't trust client complete ajax call in onbeforeunload alone, don't how function works in top browsers.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -