11

I have a registration system on my website which uses the common activation email trick. This email simply contains instructions and a link to the activation page on my website. So suppose I registered on the site, opened a new tab to check my emails and then clicked on the link, which will open in another new tab, resulting in two tabs open on the site (of which one is btw still telling them to o check their mail).

Is there a way to get the link in the email to open in the first tab on my website? (Or open a new tab if the previous one was closed or moved to another domain).

Thanks for any help/suggestions!

Sean Bone
  • 3,368
  • 7
  • 31
  • 47
  • I don't think this is possible, but if it was it would be fantastic (IMO), although someone might have browsed to a new page in the other tab and might not necessarily want it to be redirected to the activation page. – Bojangles Aug 23 '12 at 11:48
  • @JamWaffles I agree! :) Ideally it would check if there's a tab open on my domain and: if there is, open the link in that one, if there isn't open it in a new tab, as normal. – Sean Bone Aug 23 '12 at 11:52
  • Another possibility would be for the registration page to check periodically if the account has been activated and, if it has, redirect to their account page. Like this at least they wouldn't see 'Go and check your emails!'; some people get terribly confused abut this stuff (me too when testing/debugging lol) – Sean Bone Aug 23 '12 at 11:54

1 Answers1

21

You can name your current window/tab with a JavaScript assignment:

<script type="text/javascript">
    this.name = "mainWindow";
</script>

Then you use that name as value for the target attribute in links, like

<a href="nextPage.html" target="mainWindow">...

If mainWindow does not yet (or no more) exist, it will open in a new tab.

Update

The above stuff does not solve the OP's problem, because for links opened from emails, the target attribute will usually not be transferred from MUA to browser (except maybe for webmailers, but we cannot rely on this). So I was thinking of some kind of landing page which uses JavaScript to achieve the desired effect:

  1. If target window/tab `mainWindow` has already been opened, focus it, perform activation there, and close ourselves.
  2. If target window/tab does not exist, perform activation right where we are.

If this worked, you would only see a second open tab for a moment (case 1), before it closes itself. Yet it is not possible to "close ourselves", as I learned here and here - so in the end there would be a superfluous tab left, which should have been avoided. Seems like it cannot be done, sorry!

Community
  • 1
  • 1
f_puras
  • 2,521
  • 4
  • 33
  • 38
  • i had the same thought. but did you try it? – Ghassan Elias Aug 23 '12 at 11:59
  • Me? Well, yes - you can even access the window/tab via JavaScript and call functions or modify its DOM. The only restriction (AFAIK) is that both pages must originate from the same domain. – f_puras Aug 23 '12 at 12:09
  • Thanks! Yet I'm afraid this is not sufficient. You depend on how the user's MUA opens URLs in the default browser. Tried it with Thunderbird + Firefox, and it does **not** transmit the `target` attribute, so repeated clicks on the same link will open a new tab everytime. – f_puras Aug 23 '12 at 12:36
  • Thank you very much for the good answer! (+1 btw) But as you said it probably won't be enough, since "both pages must originate from the same domain"... Haven't tried it yet, but it really looks like it can't be done (also thinking of the variety of different ways people can access their mail...). :( – Sean Bone Aug 23 '12 at 13:23
  • About edit: technically it would be possible to 'close ourselves' (see [this](http://stackoverflow.com/questions/57854/how-can-i-close-a-browser-window-without-receiving-the-do-you-want-to-close-thi#1412097) answer), but it becomes a little complicated and, at least for now and for this application, not worth it. But thanks anyway for the great help, I'm sure this technique will come in handy somewhere else too! – Sean Bone Aug 24 '12 at 10:42
  • I have only found hacks which work for IE, e.g. `window.open('', '_parent', ''); window.close();`, but none for current versions of other browsers. Seems like I was trying to do just what browser makers want to prohibit... – f_puras Aug 24 '12 at 10:53
  • uh can you even run JavaScript from an email? I thought most email providers block JavaScript execution for security purposes... Oh this was posted more than 10 years ago. – Sean Patnode Apr 30 '23 at 21:20