简体   繁体   中英

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.

您可以定期从第一个选项卡检查电子邮件是否被激活然后关闭它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.

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. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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