如何在同一站点的不同页面加载中维护浏览器JavaScript中的状态? [英] How can I maintain state in browser JavaScript across different page loads from the same site?

查看:70
本文介绍了如何在同一站点的不同页面加载中维护浏览器JavaScript中的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要做一些非常简单的事情,即在不同的页面加载中维护哪个面板栏项目突出显示。我正在使用它作为一个菜单,当我点击它时,所选菜单项突出显示它看起来很好,当该菜单项的链接(页面)返回时,菜单重新加载,我失去了它。

I need to do something very simple, i.e. maintain which panel bar item is highlighted, across different page loads. I'm using this as a menu, and it looks good with the selected menu item highlighted as soon as I click it, when when the link (page) for that menu item returns, the menu is reloaded and I lose this.

我真的不想使用ajax调用来管理会话变量,如果我可以保留在本地,但我还能在哪里存储这个菜单状态?

I don't really want to use ajax calls to manage session variables just for this if I can keep in local, but where else can I store this menu state?

推荐答案

Cookies 本地存储,或者您可以对链接到的URI中的数据进行编码(例如,片段标识符)。

Cookies, local storage or you can encode the data in the URIs you link to (e.g. in the fragment identifier).

这篇关于如何在同一站点的不同页面加载中维护浏览器JavaScript中的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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