是否可以检测用户是否打开了您网站的多个标签? [英] Possible to detect if a user has multiple tabs of your site open?

查看:30
本文介绍了是否可以检测用户是否打开了您网站的多个标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在考虑整个网站注册过程.

I'm just thinking about the whole site registration process.

用户访问您的网站并注册,然后您告诉他您已向他发送了一封电子邮件,他需要验证他的电子邮件地址.所以他点击 Ctrl+T,弹出一个新标签,点击他的 Gmail 收藏按钮,没有读到你长久以来的欢迎词电子邮件,但点击他看到的第一个链接.Gmail 在另一个标签页中打开您的网站...

A user goes to your site, signs up, and then you tell him you've sent him an email and he needs to verify his email address. So he hits Ctrl+T, pops open a new tab, hits his Gmail fav button, doesn't read a word of your lengthy welcome email, but clicks the first link he sees. Gmail opens your site in yet another tab...

他不需要也不希望为您的网站打开两个标签,他只想查看在他注册之前您不允许他访问的那个该死的页面.

He doesn't need nor want two tabs for your site open, he just wants to view that darn page you've disallowed him access to until he registers.

那么我们该怎么办?我看到一个网站(但我忘记了它是什么)做得非常好,它实际上刷新了我打开的第一个标签,而无需我按下任何按钮.

So what do we do? I saw one site (but I forget what it was) that did a really good job, and it actually refreshed the first tab I had open without me having to press anything.

我在想,如果我们可以检测到用户是否已经打开了您网站的标签,我们可以自动关闭新的验证标签,或者告诉他他可以关闭它可以返回他的另一个标签(我们现在已经刷新并让他登录了).

I'm thinking, it might be nice if we can detect if the user already has a tab to your site open, we could either close the new verification-tab automatically, or tell him he can close it can go back to his other tab (which we've now refreshed and logged him in).

或者,也许当他收到您烦人的请检查您的电子邮件"消息时,他直接转到他的电子邮件,用他的电子邮件替换您的网站,他非常清楚该电子邮件会将他再次链接回该网站.在这种情况下,我们不想关闭选项卡,但也许可以保存他之前的位置,然后再次将他重定向到那里?

Or, maybe when he got your annoying "please check your email" message, he went directly to his email, replacing your site with his email knowing full well that the email will link him back to the site again. In that case, we don't want to close the tab, but maybe could have saved his location from before, and redirect him there again?

无论如何,这只是用例......问题仍然存在.我们能否检测用户是否已打开您网站的标签页?

Anyway, that's just the use case... the question still stands. Can we detect if a user already has a tab to your site open?

这个问题不是关于如何检测何时用户完成了注册过程.Ajax polling 或 comet 可以解决这个问题.我特别想知道用户是否已经打开了您网站的标签.

This question is not about how to detect when a user has completed the sign-up process. Ajax polling or comet can solve that issue. I specifically want to know if the user already has a tab open to your site or not.

推荐答案

我迟到了(一年多),但我不禁注意到你错过了一个令人难以置信的轻松和优雅解决方案(可能是您看到的那个网站使用的).

I'm fairly late to the party here (over a year), but I couldn't help but notice that you'd missed an incredibly easy and elegant solution (and probably what that website you saw used).

使用 JavaScript,您可以更改当前打开的窗口的名称:

Using JavaScript you can change the name of the window you currently have open through:

window.name = "myWindow";

然后,当您发送确认电子邮件时,只需执行以下操作(假设您发送的是 HTML 电子邮件):

Then when you send out your confirmation email simply do (assuming you're sending a HTML email):

<a href="verificationlink.php" target="myWindow">Verify</a>

这应该会导致 verificationLink 在您的网站已经加载到的窗口中打开,如果它已经关闭,它将打开一个带有指定窗口名称的新选项卡.

Which should result in the verificationLink opening up inside the window your website was already loaded into, if it's already been closed it'll open up a new tab with the window name specified.

这篇关于是否可以检测用户是否打开了您网站的多个标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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