What's the logic behind (auto-saved draft) using Javascript codes?

184 views   Javascript  2021.01.03

I mostly use Q&A sites such as Stackoverflow, Quora, when I'm interacting with form by adding some data in their input box, textarea, etc. sometimes I leave the site unexpectedly because of my device problem or slowness of network, etc. When I get back to the site they prompt me where I left off previous time by redirecting me to incomplete action(as draft). My Question is this "How do sites save data there for that period of time while it's not submitted to server or cancelled, Whats the logic behind the scenes? P.S: I'm not good at english, But I think you can get my question.

Answers, ideas and Comments

» 2 ideas

devuntildeath • 1 year ago
For historical reasons, returning a non-empty string also counts as canceling the event. Some time ago browsers used to show it as a message, but as the modern specification says, they shouldn’t. Here’s an example:

window.onbeforeunload = function() {
  return "There are unsaved changes. Leave now?";
The behavior was changed, because some webmasters abused this event handler by showing misleading and annoying messages. So right now old browsers still may show it as a message, but aside of that – there’s no way to customize the message shown to the user. readyState The load event on window triggers when the page and all resources are loaded. We rarely use it, because there’s usually no need to wait for so long. The beforeunload event on window triggers when the user wants to leave the page. If we cancel the event, browser asks whether the user really wants to leave (e.g we have unsaved changes).  »


gadrawin • 1 year ago
Let me answer your question as a developer with the help of Javascript event functions. When a user loads a page events such as DOMContentLoaded, load, are triggered along with styles and more outside scripts. On window.onunload(when user is leaves a page), this event is triggered and programmer has to add event listener with "unload", and a function to do certain things such as collecting page views, user session per page including auto-save draft Let's focus on Autosaved Draft: when you are typing text in text field, and you moved to another page for instance, that page is opened in new tab, Your data will be kept in that field waiting for you to come back, When you leave a site the draft data is stored somewhere in database for a short time and site will still remember there was a user who were commenting but they leave unexpectedly, It saves your time. Again, when you are on any page typing for example comment... meanwhile, you want to reply to incoming message some site will send you a popup message Leave site? Changes you made may not be saved. to notify you that you are not done with first action if you are still interested in commenting you will cancel that popup message, or click on Leave to quit the current page. Only for sites need reload to update a page, not for sites send data asynchronously. »


In order to go deep, share any relevant idea or posting solution to some questions, You have to sign in or create a new account if you don't have one. And get Donnekted(connected)

Log in now  Join the Team

This site is for sharing topics, questions, answers, experiences or other contents related to different stuffs, especially technology. For existing users, They can make any topic(post) to discuss about in hope for ideas or any result from other people from different communities. In order to get involved, Get donnekted(connected) by Joining us here!

Posted under this group »
This community is about sharing contents such as questions and answers discussing about Javascript and TypeScript, ES5, ES6

90 people joined this donnektish

Maintain social distancing, to avoid Covid19