让 IE“忘记”使用后退按钮时在表单中输入的信息

发布于 2024-10-11 04:30:31 字数 681 浏览 8 评论 0原文

我有一个带有表单的页面,其中许多字段都是从 URL 中传递的变量填充的。这些字段被禁用(不可编辑)并且仅供用户查看。

其余字段需要用户输入并且不能禁用(可编辑)。提交表单后,会出现确认页面。可能的情况是,用户需要提交多个这样的表单,其中各个表单的不可编辑信息是相同的,因此能够从确认页面返回到表单页面将节省大量时间。

我希望其工作方式是当用户按下后退按钮时,所有不可编辑字段都会被填充,但可编辑字段为空。这就是 Firefox 正在做的事情,但 IE8 不会“忘记”在可编辑字段中输入的内容。

要禁用缓存,以下内容将出现在我的页面开头和页面末尾。

<head>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-store"/>
<head/>

我还需要做什么才能让 IE 忘记按下后退按钮时在可编辑字段中输入的内容?

如果重要的话,我的所有页面都是用 PHP 生成的。

编辑:

在我看来,这是 IE 缓存我的页面的问题,尽管我已经告诉它不要这样做。我的 meta 标签正确吗?我需要做其他事情来阻止 IE 缓存我的页面吗?

I have a page with a form where many of the fields are populated from variables passed in the URL. Those fields are disabled (NON-EDITABLE) and are only there for the user to view.

The remaining fields require user input and are NOT disabled (EDITABLE). When the form is submitted a confirmation page comes up. It may be the case that the user needs to submit several of these forms where the NON-EDITABLE information is identical from form to form, so being able to go back to the form page from the confirmation page would save a lot of time.

The way I want this to work is when a user presses the back button all the NON-EDITABLE fields are populated, but the EDITABLE fields are blank. This is what Firefox is doing, but IE8 is does not "forget" what has been entered in the EDITABLE fields.

To disable the cache the following appears at the beginning of my page AND at the end of my page.

<head>
    <meta http-equiv="Pragma" content="no-cache"/>
    <meta http-equiv="Cache-Control" content="no-store"/>
<head/>

What more must I do to make IE forget what was entered in the EDITABLE fields when the back button is pressed?

All of my pages are generated with PHP if that matters.

EDIT:

It appears to me that this is a problem of IE caching my page even though I have told it not to. Are my meta tags correct? Do I need to do something else to prevent IE from caching my page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单 2024-10-18 04:30:31

您是否尝试过将 autocomplete='off' 属性添加到表单字段?

例如这样的东西:

<input type='text' name='myfield' size='10' autocomplete='off'>

Have you tried adding the autocomplete='off' attribute to your form fields?

eg something like this:

<input type='text' name='myfield' size='10' autocomplete='off'>
近箐 2024-10-18 04:30:31

我找到了这个代码片段,它似乎可以满足我的要求。

    <input type="hidden" id="refreshed" value="no"/>
    <script type="text/javascript">

        onload=function(){
            var e=document.getElementById("refreshed");
            if(e.value=="no"){
                e.value="yes";
            }

            else{
                e.value="no";
                location.reload();
            }

        }

    </script>   

更新:

上述解决方案在 IE 中有效,但我发现它在 Firefox 中无法正常工作。进一步探索情况,我终于在一些帮助下解决了我的问题。下面是一个更好的解决方案,将其放在 DOCTYPE 标头之上。更多详情请点击此处

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
?>

I found this code snippet and it seems to do what I want.

    <input type="hidden" id="refreshed" value="no"/>
    <script type="text/javascript">

        onload=function(){
            var e=document.getElementById("refreshed");
            if(e.value=="no"){
                e.value="yes";
            }

            else{
                e.value="no";
                location.reload();
            }

        }

    </script>   

UPDATE:

The above solution worked in IE, but I found it didn't work right in Firefox. Exploring the situation further I finally figured my issues out with some SO help. Below is a better solution, put it ABOVE your DOCTYPE header. More details here.

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
?>
月亮邮递员 2024-10-18 04:30:31

为什么不直接重定向回表单,而不是让他们点击后退按钮(有一个链接显示“输入更多”,可返回表单)?

这样,当页面加载时,您可以将输入默认为空白值

示例

<input type="textbox" name="somename" value="">

Why not just do a redirect back to the form instead of making them hit the back button (have a link saying "Enter More" that leads back to the form)?

This way when the page loads you can have your inputs default to a blank value

example

<input type="textbox" name="somename" value="">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文