简体   繁体   English

通过在Firefox中单击“后退”按钮来重新加载访问时的页面

[英]Reload the page when visited by clicking Back button in Firefox

I have a page which animates entire body out of the viewer's screen as a transition. 我有一个页面,可以将整个身体动画出观众的屏幕,作为过渡。 It works fine but when user clicks back button in the browser Firefox brings up the cached page from the history which does not have a body. 它可以正常工作,但是当用户在浏览器中单击“后退”按钮时,Firefox从没有正文的历史记录中弹出缓存的页面。

So it is simple enough for me to reload the page when visited via the back button. 因此,通过后退按钮访问页面时,重新加载页面非常简单。

I've tried the following code to reload the page so as to avoid repeted reloading. 我尝试使用以下代码重新加载页面,以避免重复加载。

<script type="text/javascript">
  window.onload=function(){
    var e=document.getElementById("refreshed");
    if(e.value=="no")e.value="yes";
    else{e.value="no";location.reload();}
  }
</script>
<input type="hidden" id="refreshed" value="no">

It did not solve the issue as the anonymous function was not even invoked. 它没有解决问题,因为甚至没有调用匿名函数。

So I tried setting the headers so that the browser would not cache the page. 因此,我尝试设置标题,以使浏览器不会缓存该页面。

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">

It also did not solve the issue. 它还没有解决问题。

The page works fine in Chrome. 该页面在Chrome中运行良好。

The version of Firefox I use is 12.0 我使用的Firefox版本是12.0

How can I get the page to reload using Javascript, JQuery or any other client side scripts ? 如何使用Javascript,JQuery或任何其他客户端脚本重新加载页面?

There is no onload event that fires when navigating back to an in-memory-cached page. 导航回内存中缓存的页面时不会触发onload事件。

You have three main options, I think: 我认为您有三个主要选择:

  1. Use the onpageshow event (which does fire when navigating to a cached page). 使用onpageshow事件(在导航到缓存的页面时触发)。
  2. Prevent in-memory caching of your page by adding an unload event listener (which can just be an empty function). 通过添加卸载事件侦听器(可以只是一个空函数)来防止页面的内存缓存。
  3. Don't do the annoying unload animation. 不要做烦人的卸载动画。

I didn't try it but setTimeout may help. 我没有尝试过,但是setTimeout可能会有所帮助。

<script>
setTimeout(function() {
var e=document.getElementById("refreshed");
    if(e.value=="no")e.value="yes";
    else{e.value="no";location.reload();}
}, 1000);
</script>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM