为什么HTML表单在浏览器后退按钮点击时,有时会被清除 [英] Why are HTML forms sometimes cleared when clicking on the browser back button

查看:131
本文介绍了为什么HTML表单在浏览器后退按钮点击时,有时会被清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信每个人都知道这种行为。您填写网上表格,你提交。提交后,你意识到你在一些错误的数据填补。所以,你点击浏览器的后退按钮。然后,有时形式仍然有您输入的数据的(你希望在这种情况下)的有时不是。

I am sure everybody knows that behaviour. You fill in a form on the web, and you submit it. After the submission you recognize that you filled in some wrong data. So, you click on the browsers back button. Then, sometimes the form still have the data you entered (what you are hoping in this situation) and sometimes not.

当它被清除,我找不到任何连接的时候不行。

I couldn't find any connection when it is cleared and when not.

一些答案​​,我在互联网上/计算器发现:

Some answers i found on the internet / stackoverflow:


  • 在HTTPS连接,形式总是清零

  • 使用带有会议动态网站时,表单总是被清零

但两者都是definatly错误的。我所看到的网站(如我自己的一种),它的浏览器之后保持表单数据回使用HTTPS 正在使用的会话。

But both of them are definatly wrong. I have seen sites (like one of my own) that does keep the form-data after the browser back and are using https and are using sessions.

所以,请:有谁能够给我解释一下如何浏览器处理这东西

So please: can anybody explain me how browsers are handling this stuff?

顺便说一句:我的任务是确保表单数据的不可以清除

By the way: my task is it to make sure that the form data is not cleared.

推荐答案

我不能代表所有的情况提供明确的答案。

I can't provide the definitive answer for all scenarios.

作为Web开发人员,这里是我一般遵循我开发的网站,实现不让用户丢失数据的目标的规则:

As a web developer, here's the rule I generally follow for sites I develop, to accomplish the goal of not letting the user lose data:


  • 禁用你想留在网页上的所有缓存(通过HTTP头)。

  • 捕获所有的数据到会话(或其他临时存储),当表单被提交。

  • 如果用户向后导航,浏览器请求的页面的新版本(因为你将其设置为从不缓存)。

  • 的页面有逻辑地望向会话/数据库/地方并重新填充根据最后输入状态的所有字段。如果有在页面上输入的动态,你应该有足够的数据来重新创建。

  • 一旦这个过程完成后,使用POST /重定向/ GET方式来清除会话数据并使其用户很难回到原来的页面。

一些答案​​,我在互联网上/计算器发现:结果
   1. HTTPS连接,形式总是清零结果
   2.使用带有会议动态网站时,表单总是被清零

Some answers i found on the internet / stackoverflow:
1. on https connections, forms are always cleared
2. when using dynamic websites with sessions, forms are always cleared

我相信#1通过浏览器/安全设置/场景而异。

I believe #1 varies by browser/security settings/scenario.

假设#2肯定不是在所有情况下,真正的(我刚才所描述的模式的利用的会话,动态表单)。

Assumption #2 is certainly not true in all cases (the pattern I just described leverages session and dynamic forms).

这篇关于为什么HTML表单在浏览器后退按钮点击时,有时会被清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆