Chrome在浏览器后退按钮上再次执行所有JS [英] Chrome executing all JS again on browser back button

查看:725
本文介绍了Chrome在浏览器后退按钮上再次执行所有JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序。我写了一些JS脚本,准备在文档上执行。但是在Chrome中,当我们点击后退按钮并返回上一页时,它将再次执行所有js脚本。但是,当我在firefox上使用它时,它不执行JS。

I am developing a web application. And I wrote some JS script to be executed on document ready. But in chrome when we click on back button and go back to previous page it is executing all the js script again. But when I use same on firefox it do not execute the JS.

我在页面上有一个手风琴,当用户打开任何手风琴并进入下一个链接手风琴之后,如果再次点击手风琴页面上的后退按钮,chrome将关闭所有的手风琴,因为我已经编写了脚本将所有这些文件关闭。但是Firefox不会关闭。

I have an accordion on a page and when user open any accordion and go on one of the link under the accordion and after that if again clicks the back button on the accordion page chrome is closing all the accordions as I have written the script to close all these on document ready. But firefox do not close.

有什么方法可以解决这个问题吗?因此,我可以放置任何条件,如 if(history.forward.length< 1){do this ....}

Is there any way to fix this with javascript? So that I can put any condition like if(history.forward.length < 1){ do this....}

推荐答案

我想到的解决方案是使用sessionStorage来了解它是否是第一次加载或不加载。或者更好的是,您可以保留会话存储中的手风琴状态,以便始终以用户所需的方式操作。

The solution that came to my mind is using sessionStorage to know if it is a first time loading or not. Or even better, you can keep state of your accordions in session storage so it always be the way the user want.

这篇关于Chrome在浏览器后退按钮上再次执行所有JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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