简体   繁体   English

浏览器标签/窗口跟踪模式?

[英]Browser Tab/Window tracking pattern?

Is there an accepted pattern for tracking that a page is being loaded by the same tab/window? 是否存在接受的模式来跟踪同一标签页/窗口正在加载页面?

There are certain processes (like stepped submission processes), which can greatly benefit from a ability to verify that the same tab is asking for execution. 有某些过程(如分步提交过程),可以从验证同一选项卡要求执行的功能中受益匪浅。

For example, there are places where (between steps) we store intermediate data in memcache, but this can cause a problem without the ability to scope that data to this process, as opposed to if the user opens another tab/window on the same process. 例如,在某些地方(在步骤之间)我们将中间数据存储在内存缓存中,但这会导致问题,无法将数据范围限定在过程中, 与用户是否在同一过程中打开另一个选项卡/窗口相反。

This holds true for many actions/processes. 这对于许多动作/过程都适用。

Some brainstorming has not come up with anything dependable. 一些头脑风暴还没有得出任何可靠的结论。

Ideas anyone? 有任何想法吗?

You could maintaining the state of a multi-step process using query parameters (if you use GET requests) or hidden fields (if you use POST requests) or both (if you POST-then-redirect, to allow the user to refresh her browser). 您可以使用查询参数(如果使用GET请求)或隐藏字段(如果使用POST请求)或同时使用两者(如果使用POST-然后-重定向)来维持多步骤过程的状态,以允许用户刷新浏览器)。

If you maintain state on the server (eg in a DB or memcached) you could just keep a "transaction key" in a query parameter or hidden field. 如果您维护服务器上的状态(例如,在数据库或内存缓存中),则只需在查询参数或隐藏字段中保留“事务键”即可。

Be wary, though - in my experience, it's possible to design such a stateful multi-stage process fairly cleanly, but it may be tricky to implement and to maintain a non-surprising user experience. 但是要警惕-以我的经验,可以相当干净地设计这种有状态的多阶段流程,但是实现和维持不令人惊讶的用户体验可能很棘手。 For example, what happens when you move back and forth between the stages? 例如,当您在各个阶段之间来回移动时会发生什么? You could allow this explicitly, or the user could use the back button, but the process should still make sense. 您可以明确允许这样做,或者用户可以使用“后退”按钮,但是该过程仍然有意义。

EDIT: 编辑:

As a concrete example: 作为一个具体的例子:

  1. User clicks "Start multi-step process", which does a POST to the server 用户单击“启动多步过程”,这将对服务器执行POST
  2. Server then 然后服务器
    • initializes state for a process 初始化进程的状态
    • gives it unique key "A" 给它唯一的键“ A”
    • keeps it in a temporary store (eg memcached) 将其保存在临时存储中(例如memcached)
    • redirects the user to "/process/A/step/1" 将用户重定向到“ / process / A / step / 1”
  3. The next step for the process would be "/process/A/step/2" 该过程的下一步将是“ / process / A / step / 2”
  4. User, in a different tab, clicks "Start multi-step process" again 用户在另一个选项卡中,再次单击“开始多步过程”
  5. Server does the same but 服务器执行相同的操作,但是
    • uses a unique key "B" 使用唯一键“ B”
    • redirects to "/process/B/step/1" 重定向到“ / process / B / step / 1”
  6. The next step for this second process would be "/process/B/step/2" 第二个过程的下一步将是“ / process / B / step / 2”
  7. The two processes now have independent server-side state 这两个进程现在具有独立的服务器端状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM