为什么Firefox 5会忽略document.ready? [英] Why does Firefox 5 ignore document.ready?

查看:105
本文介绍了为什么Firefox 5会忽略document.ready?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Firefox 5.0.1在按下后退按钮时不刷新这个页面?

 < html> 
< head>
< meta http-equiv =cache-controlcontent =no-cache>
< script src =http://code.jquery.com/jquery-1.6.2.min.jstype =text / javascript>< / script>
< script>
$(document).ready(function(){alert('ready');});
$(window).load(function(){alert('load');});
< / script>
< / head>
< body>
< form action =http://www.google.commethod =get>
< input name =qtype =text>
< input type =submit>
< / form>
< / body>
< / html>

重现步骤:






  1. 无论是document.ready还是window.load都会被触发



  2. 更新:

    这将强制firefox重新加载页面:

      $(window).unload(function(){}); 

    但是,我结束了使用这个:

      window.addEventListener('pageshow',function(){alert('pageshow');},false); 


    解决方案


    .1当后退按钮被按下时不刷新这个页面?

    因为它不需要。



    当您在Firefox中返回时,Firefox可以从后退按钮缓冲区中完全加载页面,那么您将返回的不是新页面,而是确切的页面状态你之前离开它,就好像之间没有任何事情发生,包括所有你的Javascript代码和变量的状态。就你的脚本(和jQuery)而言,ready()已经被触发了。如果它已经被解雇,jQuery将不会再次触发它。



    您可能需要的是监听pageshow事件,当页面从缓冲区重新加载时,即使其状态完全保留,Firefox也会触发这个事件。


    Why does Firefox 5.0.1 not refresh this page when the back button is pressed?

    <html>
    <head>
      <meta http-equiv="cache-control" content="no-cache">
      <script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>   
      <script>
      $(document).ready(function() { alert('ready'); });
      $(window).load(function() { alert('load'); });
      </script>
    </head>
    <body>
      <form action="http://www.google.com" method="get">
      <input name="q" type="text"> 
      <input type="submit">
      </form>
    </body>
    </html>
    

    Steps to reproduce:

    1. Click "Submit Button"
    2. Press Back
    3. Neither document.ready or window.load fires

    Update:

    This will to force firefox to reload the page:

    $(window).unload(function() {});
    

    But, I ended up using this:

    window.addEventListener('pageshow', function() {alert('pageshow'); }, false);
    

    解决方案

    Why does Firefox 5.0.1 not refresh this page when the back button is pressed?

    Because it doesn't need to.

    When you go "back" in Firefox and Firefox can load the page entirely from the back button buffer, then what you are going back to is not to a fresh page but to the page in the exact state you left it before as if nothing had happened in between, and that includes the state of all your Javascript code and variables. As far as your script (and jQuery) is concerned, ready() has already fired. jQuery will not fire it a second time if it's already fired.

    What you probably want is to listen to the 'pageshow' event, which Firefox fires when the page is re-loaded from the buffer, even if its state is fully preserved.

    这篇关于为什么Firefox 5会忽略document.ready?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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