防止后退按钮显示POST确认警报 [英] Prevent Back button from showing POST confirmation alert

查看:125
本文介绍了防止后退按钮显示POST确认警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序向Web页面提供长参数列表,所以我必须使用POST而不是GET。问题是,当显示页面并且用户点击后退按钮时,Firefox会显示一个警告:


要显示此页面,Firefox必须发送信息将重复之前执行的任何操作(例如搜索或订单确认)。


由于应用程序是内置的返回是一种很常见的操作,这对于最终用户来说真的很烦人。



基本上,我想按照这个页面的方式来做:

>

http://www.pikanya.net/testcache/



输入内容,提交,并点击返回按钮。没有任何警告,它只是返回。



谷歌搜索,我发现这可能是Firefox 3中的一个错误,但我想以某种方式获得这种行为,即使他们修理它。



我猜这可能适用于一些HTTP头文件,但究竟是哪一个?

解决方案 div>

一种方法是将POST重定向到一个重定向到GET的页面 - 请参阅发布/重定向/获取wikipedia



假设您的POST是4K的表单数据。据推测,你的服务器用这些数据做了一些事情,而不是只显示一次并扔掉它,比如将它保存在数据库中。继续这样做,或者如果它是一个巨大的搜索表单,可以在数据库中创建一个临时副本,在使用空间限制后的几天或LRU基础上进行清除。现在创建一个可以使用GET访问的数据表示。如果它是临时的,则为其生成一个ID并将其用作URL;如果它是一组永久数据,它可能有一个ID或可用于URL的内容。在最糟糕的情况下,像小型网址使用的算法可以将较大的网址折叠为较小的网址。重定向POST以获取数据表示。






作为历史记录,这项技术是 1995年的惯例


I have an application that supplies long list of parameters to a web page, so I have to use POST instead of GET. The problem is that when page gets displayed and user clicks the Back button, Firefox shows up a warning:

To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.

Since application is built in such way that going Back is a quite common operation, this is really annoying to end users.

Basically, I would like to do it the way this page does:

http://www.pikanya.net/testcache/

Enter something, submit, and click Back button. No warning, it just goes back.

Googling I found out that this might be a bug in Firefox 3, but I'd like to somehow get this behavior even after they "fix" it.

I guess it could be doable with some HTTP headers, but which exactly?

解决方案

One way round it is to redirect the POST to a page which redirects to a GET - see Post/Redirect/Get on wikipedia.

Say your POST is 4K of form data. Presumably your server does something with that data rather than just displaying it once and throwing it away, such as saving it in a database. Keep doing that, or if it's a huge search form create a temporary copy of it in a database that gets purged after a few days or on a LRU basis when a space limit is used. Now create a representation of the data which can be accessed using GET. If it's temporary, generate an ID for it and use that as the URL; if it's a permanent set of data it probably has an ID or something that can be used for the URL. At the worst case, an algorithm like tiny url uses can collapse a big URL to a much smaller one. Redirect the POST to GET the representation of the data.


As a historical note, this technique was established practice in 1995.

这篇关于防止后退按钮显示POST确认警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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