Opening links in a specific tab - from an email

2020-06-17 06:01发布

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!

1条回答
欢心
2楼-- · 2020-06-17 06:45

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!

查看更多
登录 后发表回答