当用户关闭浏览器时处理未保存的表单数据

当用户关闭浏览器时处理未保存的表单数据

本文介绍了当用户关闭浏览器时处理未保存的表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在关闭浏览器或用户更改页面时,我很难找出如何自动保存用户数据的形式。当您要打开对话框时, onBeforeUnload事件可以,但是此时保存更改已为时已晚(除非您只是在onBeforeUnload处理程序中阻止浏览器足够长的时间才能将请求传递到服务器...但是我不想这样做)。I'm having hard time trying to figure out how to auto-save user data in a form when the browser is being closed or user changes the page. The onBeforeUnload event is OK when you want to open a dialog box, but by then it's too late to save the changes (except if you just block the browser in the onBeforeUnload handler long enough for it to pass the request to the server...but I'd rather not do that).我确定你们中有些人必须处理未保存的表单问题。你是做什么?您是否:I am sure some of you have had to deal with the unsaved form problem. What do you do? Do you: 让用户只是丢掉他们的更改, 使用模式窗口询问他们是否确定自己做了正确的事, 在更改时迅速保存单个字段 , 还是您有一些终极方法来自动保存数据,这些数据将不可避免地丢失?let users just lose their changes,ask them using a modal window if they are sure they did the right thing,save individual fields on the fly as they change,or do you have some ultimate method to automagically save the data when it's about to be lost irretrievably?推荐答案我喜欢您的第三个选择:I like your third option: I'我必须处理类似的情况,这就是我们正在做的。卖给我的两个主要因素是:I'm having to deal with a similar situation, and that's what we are doing. The two main things that sell that to me: 改善的用户体验-$的形式给用户留下了深刻的印象, b $ b不会丢失更改。一旦通过验证,它们就是承诺的 。 例如,他输入一个有效的电子邮件地址,该地址会立即保存,此外,还会为的每个字段(为成功)提供某种形式的反馈已保存(例如,绿色的刻度,出现在字段旁边)。 没有其他内容了,哦,我的浏览器当机了并且我丢失了所有信息。Improved user experience - the userwill be impressed by a form thatdoes not lose changes. They are'committed' once they are validated.E.g., he types in a valid emailaddress, and it is saved instantly,furthermore he is provided some sortof feedback for each field that issuccessfully been saved (a greentick for example, appears next tothe field).No more 'oh crap my browser crashedand I lost all my info' situations.缺点:开发此类解决方案需要花费额外的工时,并可能最终没有像一个简单的解决方案那样好。也就是说,IMO仍然值得。Disadvantages: The extra man-hours involved in developing such a solution, and the possibly that it ends up not degrading as nicely as a simpler solution. That said, it is still worth it IMO. 这篇关于当用户关闭浏览器时处理未保存的表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-18 23:44