当按下返回按钮时,如何使Firefox重新加载页面? [英] How do I make Firefox reload page when back button is pressed?

查看:185
本文介绍了当按下返回按钮时,如何使Firefox重新加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有应该阻止页面被缓存的meta标签的组合和排列,但Firefox仍然缓存页面! 在IE8中正常工作。



我试过了所有这些。 。

 < meta http-equiv =Cache-Controlcontent =no-store/> 
< meta http-equiv =Pragmacontent =no-cache/>
< meta http-equiv =Expirescontent = - 1/>
< meta http-equiv =Expirescontent =Sat,1 Jan 1 00:00:00 GMT/>

...我也尝试了以下JavaScript ...

 < input type =hiddenid =refreshedvalue =no/> 
< script type =text / javascript>

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

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

}

< / script>

...一切都无济于事。我在这里错过了什么?如果有问题的话,页面将由PHP生成。



更新1:



到目前为止已经尝试了所有的建议,但我仍然无法得到这个工作。当我使用克里斯的PHP代码,我使用它像这样...

 <?php 
header -Control:no-store,no-cache,must-revalidate,max-age = 0);
header(Expires:Sat,26 Jul 1997 05:00:00 GMT);
?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
< html dir =ltrxmlns =http://www.w3.org/1999/xhtml>
<! - 我的其余页面 - >

..正如您所看到的,它位于网页的EXTREME顶部,
$ b

我也尝试过使用 session_start()但即使阅读手册后,我不确定我是否正确使用。我正在把它放在我的页面的顶部。

我对任何建议都是开放的,它使得这个工作不会破坏其他页面功能。我知道我已经看到每次重新加载后退按钮的页面,它们是如何操作的!



已解决!



原来我有多个问题对我不利,但通过尽职调查,我能够消除这些问题并获得胜利。



在Chris将他的代码更新为...

 <?php 
header( Cache-Control:no-store,no-cache,must-revalidate,max-age = 0);
header(Expires:Sat,26 Jul 1997 05:00:00 GMT);
echo time();
?>< a href =http://google.com> aaaaaaaaaaaaa< / a>

我发现他的代码在我使用它的时候的确如此,除此之外,但是当我把它放进我的页面时,它不起作用。我的所有页面都是 .php .html ,并且都附加到DWT(动态Web模板),所以我用Chris的代码一次性更新了所有的代码。我没有意识到,DWT在 DOCTYPE 标题后面开始,所以代码从未插入到我的页面中。我无法找到使DWT包含 DOCTYPE 标题的方法,所以我进入了所有的页面,并手动在 DOCTYPE .htm code> .html 作为 .php .html 页面生成错误在我已经插入克里斯的代码说什么的效果,不能修改标题,头已经发送的地方。我并不关心我的扩展是什么,所以我只是将所有的 .html 扩展名改为 .php 扩展名。

最后一个小问题是,即使页面没有被缓存(就像我想的那样),Firefox会把用户放在上一页的最后一个位置他们使用后退按钮(即,如果用户在页面a的底部,当他们导航到页面b时,则用户使用页面b上的后退按钮,他们将被返回到页面a的底部,而不是页面的顶部根据需要)。修剪下我原来的JavaScript修正了这个问题...

 < script type =text / javascript> 

onload = function(){
document.getElementById('content')。scrollTop = 0;
}

< / script>

虽然这个问题似乎非常复杂,但我很高兴这个问题已经解决了。感谢您的帮助,每个人(特别是克里斯)。

解决方案

这适用于我



创建一个新的php文件。

 <?php 
header( Cache-Control:no-store,no-cache,must-revalidate,max-age = 0);
header(Expires:Sat,26 Jul 1997 05:00:00 GMT);
echo time();
?>< a href =http://google.com> aaaaaaaaaaaaa< / a>


I have tried every combination and permutation of meta tags that are supposed to stop a page from being cached, but Firefox STILL caches the page! I just need the URL to reload when a user presses the back button. Works fine in IE8.

I have tried all of these...

<meta http-equiv="Cache-Control" content="no-store" />
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="-1"/>
<meta http-equiv="Expires" content="Sat, 1 Jan 2000 00:00:00 GMT" /> 

...and I have also tried the following JavaScript...

<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> 

... all to no avail. What am I missing here? Pages are generated with PHP if that matters.

UPDATE 1:

I have tried every suggestion thus far but I still cannot get this to work. When I use Chris's PHP code I use it like this...

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<!--the rest of my page-->

.. and as you can see it is at the EXTREME top of my webpage, before the DOCTYPE header.

I have also experimented with session_start() but even after reading the manual I am not sure I am using it right. I was putting it right at the very top of my page as well.

I am open to ANY SUGGESTIONS that make this work without breaking other page functionality. I know I have seen pages that reload EVERY TIME the back button is used, HOW ARE THEY DOING IT?!

SOLVED!

Turns out I had multiple issues working against me, but through due diligence I was able to eliminate those issues and emerge victorious.

After Chris updated his code to...

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
echo time();
?><a href="http://google.com">aaaaaaaaaaaaa</a>

I found that his code did indeed work when I used it EXACTLY how he had it with NOTHING else, but when I put it into my pages it didn't work. All of my pages are either .php or .html and all are attached to a DWT (Dynamic Web Template), so I was updating all of them at once with Chris's code. What I didn't realize was that the DWT starts RIGHT AFTER the DOCTYPE header, so the code was never inserted into my pages. I could find no way to make the DWT include the DOCTYPE header so I went into all my pages and manually inserted the code above the DOCTYPE header.

Next I found that even though my server is set to parse .htm and .html as .php the .html pages were generating an error at the very where I had inserted Chris's code saying something to the effect of "cannot modify headers, headers have already been sent". I didn't really care what my extensions were so I just changed all my .html extensions to .php extensions.

A final minor annoyance was that even though the page was now not being cached (just like I wanted) Firefox was placing the user at their last location on the previous page when they used the back button (i.e. if a user was at the bottom of page a when they navigated to page b, then the user used the back button on page b they would be returned to the bottom of page a, not the top of page a as desired). Trimming down my original JavaScript fixed this...

    <script type="text/javascript">

        onload=function(){
            document.getElementById('content').scrollTop=0;
        }

    </script>

Even though this seems very involved for such a simple problem I am glad it is fixed. Thanks for your help everyone (especially Chris).

解决方案

This works for me

make a new php file. I can use the back and forward buttons and the number on the page always updates

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
echo time();
?><a href="http://google.com">aaaaaaaaaaaaa</a>

这篇关于当按下返回按钮时,如何使Firefox重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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