存储浏览器标签的特定数据 [英] Store browser tab specific data

查看:112
本文介绍了存储浏览器标签的特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序,用于存储有关最近访问的页面的信息,我们称它们为A.当用户访问另一种页面类型(称为B)时,我在顶部显示一个菜单,并带有一个按钮,指向最近访问的A -页.可以通过A页或B页访问B页,并且用户可以将其视为A的属性.

I have a web application that store information about recently visited pages, let's call them A. When a user visits another page type, called B, I render a menu at the top with a button to point to the most recently visited A-page. The B-pages are accessible either through an A page or a B page and can by the user be considered a property of A.

这可以很好地工作,但是当有人打开两个选项卡并且在选项卡1中的B页上具有指向A页A1的链接时,他们会打开一个新选项卡并访问A页A2,这将成为一个问题.然后,用户刷新选项卡1中的B页时,菜单更改为A2.我希望能够确定正在使用的标签页,以便可以将A1保存为标签页1,这样它就不会更改为A2.

This works fine but it becomes a problem when someone opens two tabs and when being on a B-page in tab 1 with a link to the A-page A1 they open a new tab and visits the A-page A2. When the user then refreshes the B-page in tab 1 the menu changes to A2. I'd like to be able to identify what tab is being used so that I can save A1 for tab 1 so that it doesn't change to A2.

使用一个标签时:

A1 -> B1 -> B2 (the menu points back to A1)

使用两个标签时:

Time            | T1       | T2       | T3          
----------------+----------+----------+-------------
Tab 1:          | A1 -> B1 |          | [refresh B1]
Tab 2:          |          | A2 -> B3 |             
----------------+----------+----------+-------------
Menu points to: | A1    A1 | A2    A2 | A2

当用户返回到选项卡1时,会遇到他们正在选项卡2(A2)而非A1中查看的用户.

This confuses the users when they back in tab 1 comes to the user they were viewing in tab 2 (A2) instead of A1.

恐怕无法获得浏览器选项卡ID,但有人可能有解决方法的想法吗?

I'm afraid that it isn't possible to get the browser tab ID but someone might have any ideas of a workaround?

推荐答案

编辑:时间的流逝使我从2012年起的原始答案不正确.如Bedrin所指出,您现在可以使用 Window.sessionStorage对象:

The passage of time has rendered my original answer from 2012 incorrect. As bedrin points out, you may now use the Window.sessionStorage object:

sessionStorage属性允许您访问当前来源的会话存储对象. sessionStorage与Window.localStorage相似,唯一的区别是,存储在localStorage中的数据没有设置过期时间,存储在sessionStorage中的数据在页面会话结束时被清除.页面会话的持续时间只要浏览器处于打开状态,并且在页面重新加载和还原后仍然存在.在新标签页或窗口中打开页面将导致启动新会话,这与会话Cookie的工作方式不同.

The sessionStorage property allows you to access a session Storage object for the current origin. sessionStorage is similar to Window.localStorage, the only difference is while data stored in localStorage has no expiration set, data stored in sessionStorage gets cleared when the page session ends. A page session lasts for as long as the browser is open and survives over page reloads and restores. Opening a page in a new tab or window will cause a new session to be initiated, which differs from how session cookies work.

原始答案(2012年):

恐怕这无法通过便携式方式实现,因为您发现自己无法检索浏览器选项卡ID之类的内容.据我所知,HTML标准完全不了解浏览器中的选项卡.

I am afraid this won't be possible in a portable way, as you have found out yourself it is not possible to retrieve something like a browser tab ID. The HTML standards are, as far as I am aware, completely unaware of tabs in browsers.

我能想到的唯一解决方法是:在应用程序中实现和管理选项卡.我已经看到了几个实现此目的的Web应用程序,但是(imho)用户体验非常糟糕.

The only workaround I can think is would be this: Implement and mange tabs in your application. I have seen several business web applications that do this, but (imho) the user experience is quite bad.

这篇关于存储浏览器标签的特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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