简体   繁体   English

关闭浏览器选项卡

[英]Close browser tab

I have a page that tells users to go to their email and click verification link. 我有一个页面,告诉用户转到他们的电子邮件并单击验证链接。 When they do, the link in the email message opens a new tab, so now the user has two tabs open, both related to email, which is a bit confusing. 当他们这样做时,电子邮件中的链接会打开一个新选项卡,因此现在用户打开了两个选项卡,这两个选项卡都与电子邮件相关,这有点令人困惑。

  • Is there any chance to have them click the link in their email and open confirmation within the first tab or 有没有机会让他们点击他们的电子邮件中的链接并在第一个选项卡中打开确认或

  • Open the new tab but at the same time close the original tab? 打开新选项卡,但同时关闭原始选项卡?

There's gotta be way with JS, I hope. 我希望,JS必须有办法。

您可以定期从第一个选项卡检查电子邮件是否被激活然后关闭它window.close() ,因此剩下的打开选项卡将是第二个,通常,您将使用setInterval和ajax请求实现类似的服务器后端检查电子邮件是否已激活。

No, but you could run a Javascript in your first tab that pings your server every 10 seconds or so, to check if the account was confirmed. 不,但您可以在第一个选项卡中运行Javascript,每隔10秒左右ping一次服务器,以检查帐户是否已确认。

If it was, then the page redirects itself to the new user's dashboard (or some other "main account page"). 如果是,则页面将自身重定向到新用户的仪表板(或其他一些“主帐户页面”)。

setInterval(function(){
    $.get('/api/is_confirmed.php').then(
        function(response){
            if (response.status_code == '200')
                window.location = '/dashboard.php';
        }
    );
}, 10000);

I would advise against self.close() ing the window. 我建议反对self.close()窗口。 Do not interfere with the user's control of the browser tabs. 不要干扰用户对浏览器选项卡的控制。 Having tabs suddenly disappear by themselves is unexpected for the user and annoying at best, frightening at worst. 突然消失的标签对于用户来说是意料之外的,并且最好是令人讨厌,最糟糕的是可怕。

One thing you could do is: 你能做的一件事是:

1- Instead of having a link to your page in that email, put a link to a special page that changes a database value then closes itself. 1-不要在该电子邮件中添加指向您页面的链接,而是将链接添加到更改数据库值的特殊页面,然后自行关闭。

2- On the main page, have a thread constantly poll that database value and as soon as you see the change, update the page with ajax (or refresh) then bring the broser on top of other windows. 2-在主页面上,让一个线程不断轮询该数据库值,并在看到更改后立即使用ajax(或刷新)更新页面,然后将更明亮的内容置于其他窗口之上。

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

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