简体   繁体   English

在任何浏览器上单击后退按钮时,表单中的数据都会丢失(Django)

[英]lose data in the form when clicking the back button on any browser (Django)

My current application has a form which the user fills and hits the submit button to get the output data. 我当前的应用程序具有用户可以填写并点击“提交”按钮以获取输出数据的表单。 But, I loose all the data which was entered into the form when I click the back button on the browser. 但是,当我单击浏览器上的“后退”按钮时,我丢失了输入到表单中的所有数据。 All the drop down select list get reset to initial setting. 所有下拉选择列表都将重置为初始设置。

Is there a way where I can store these inputted values and populate it back when the user hits the back button. 有没有一种方法可以存储这些输入的值,并在用户单击“后退”按钮时将其填充回去。 I want to avoid the user from entering the values into the from again and again.. 我想避免用户一次又一次地将值输入到中。

Thanks 谢谢

One way of doing it is to use the Javascript beforeunload event, which occurs when you navigate away from a page, then to store the data in a cookie. 一种方法是使用Javascript beforeunload事件,该事件在您离开页面导航时发生,然后将数据存储在cookie中。 When the user comes back, you could check for the cookie's existance and content, and repopulate the fields with that data. 当用户回来时,您可以检查cookie的存在和内容,然后用该数据重新填充字段。

This is my first reply on StackOverflow, so I hope it was helpful! 这是我对StackOverflow的第一个答复,因此希望对您有所帮助! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 浏览器返回按钮后刷新 Django 向导窗体 - Refresh Django wizard form after browser's back button 如何防止浏览器在Django中导航时重新填充表单数据 - How to prevent browser from refilling form data when navigating back in Django 当单击后退按钮时,显示表单时,Django CreateView允许重新提交数据 - Django CreateView allows resubmission of the data when the form is displayed when hiting the back button 浏览器后退按钮行为django - Browser back button behaviour django Django-即使在通过单击浏览器中的“后退”按钮从加载的页面注销后仍进行Ajax调用 - Django - Ajax call made even after logout from a page loaded by clicking back button in browser Django - 用户在注销后单击浏览器后退按钮重新进入会话 - Django - User re-entering session by clicking browser back button after logging out 如何通过单击按钮在后台提交Django表单? - How to submit Django form in the background by clicking a button? 如何在 Django 中禁用浏览器后退按钮? - How to disable browser back button in django? Django - 单击表单中的按钮时显示加载消息、弹出窗口、屏幕或图标 - Django - Display a loading message, popup, screen or icon when clicking a button in form Django:never_cache 不起作用,它仍然在浏览器后退按钮上显示相同的数据 - Django: never_cache is not working, it still shows same data on browser back button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM