在Firefox中的“后退"按钮上还原对象类 [英] Restore object classes on back button in Firefox

查看:45
本文介绍了在Firefox中的“后退"按钮上还原对象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我有一个表格.最初,输入元素具有未填充"类.填写表单后,我会动态删除该类.

  1. I have a form. Initially an input element has the class "unfilled". As the form is filled out I dynamically remove the class.

表单已提交,并且重定向到另一个页面.

The form is submitted and there is a redirect to another page.

我单击后退"按钮并返回到原始表单,但是元素缺少未填充"类.

I click the "back" button and come back to the original form, but the element is missing the "unfilled" class.

这不是IE8中的问题. 我尝试添加此jQuery调用,但是通过后退按钮到达页面时不会执行该调用:

This not a problem in IE8. I tried adding this jQuery call, but it is not executed when the page is reached via back button:

$('#my_input').hasClass('unfilled')

谢谢!

对不起,上面的代码行写错了.应该是:

edit: Posted the wrong line of code above, sorry. Should be:

$(document).ready(function() {
    $('#my_input').addClass('unfilled')

推荐答案

Firefox维护了一个称为bfcache的内容(在此处了解更多信息),该方法基本上将页面的整个状态缓存在内存中,并在您返回时将其恢复. onload脚本不会再次执行,并且元素保持与之前相同的状态.您可以通过向页面添加虚拟onunload处理程序来禁用此行为.

Firefox maintains something called a bfcache (read more here), that basically caches the entire state of the page in memory and restores it when you go back. onload scripts are not executed again and elements stay in the same state they were in before. You can disable this behaviour by adding a dummy onunload handler to your page.

这篇关于在Firefox中的“后退"按钮上还原对象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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