Solution 1 :

You can close one of the tabs by using window.close();.

Here is a working example with two files:
The following logic closes the tab after 3 seconds.

enter image description here


<h1>Confirm your email by clicking on the below button</h1>
<a href="http://localhost/confirm.php" target="_blank">Click here to confirm</a> 


function timeToClose(){

    setTimeout(function(){ window.close(); }, 3000); // or some other logic

Thank you for confirming your email.

Problem :

I have user registration process where at the end of it an email is sent to the registering user to confirm the user’s email. The user then goes to his/her email and finds the email with the confirmation link.

At this point the user has two tabs open (but can have more) – the email tab and the tab to my domain, lets call it

Is it possible, that when the user clicks the confirmation link in the email that the tab thats already open gets updated?

Right now when the user clicks the confirmation link, a new tab to gets created, which creates two instances to the site, which is fine but not ideal.

I know I can create a function that periodically checks if the user confirmed or open a websocket, but I am wondering if there is something simpler.


Comment posted by Darkisa

This works if you own the domain and are confirming through your domain but not if you’re confirming via email. The “click to confirm your email” will be in your email tab so if you use gmail, the tab thats open where you’re confirming is, which you have no control over.

Comment posted by Saif

I am assuming they already have your site open in one tab, and in another they have their email open. Now if they click the link present in that email, either it opens a new tab or in the same tab. In both the cases, it is your website that they are opening, if you close that tab, you’re done (because they already have your site open in one more tab).