-1

I have strange functionality requirement. There are two websites which has link of each other. Clicking the link opens other website in a new tab.

However, when the other website is already open in a tab, all i want on button click is to refresh the existing tab instead of opening a new tab.

Is it possible implement this? And on all the browsers?

EDIT: This is different from other SO questions mentioned in the comments since user can open both the websites directly as well and in that case suggested answers doesn't work.

Gautam Kumar
  • 941
  • 2
  • 16
  • 37
  • @AdrianoRepetti user can open both the websites directly as well and in that case suggested answer doesn't work. – Gautam Kumar Apr 16 '15 at 11:41
  • @user2779912 if they have been opened independently then there is nothing you can do (unless you have some sort of timed server side help): for security reasons tabs are completely separated. – Adriano Repetti Apr 16 '15 at 11:45
  • @AdrianoRepetti Thanks for the help. I am setting window.name = "somename" in the first website; I open the first website independently. And while opening the website from 2nd one, i am using window.open("website.name", 'somename'); and still it doesn't work. Can you please explain why? – Gautam Kumar Apr 16 '15 at 11:58

1 Answers1

2

You can do it like this:

<a href="otherpage.html" target="other-page">Click here</a>

The first time you click that link the page will open in a new tab, but the next times it will refresh the same tab instead.

That's how WordPress refreshes the preview when writing posts.

Edit: This will only work if the other page is opened with this link.

andeersg
  • 1,505
  • 2
  • 13
  • 24
  • Ah sorry, i did not see those links before answering. – andeersg Apr 16 '15 at 11:49
  • Thanks for the help. I am setting window.name = "somename" in the first website; I open the first website independently. And while opening the website from 2nd one, i am using window.open("website.name", 'somename'); and still it doesn't work. Can you please explain why? – Gautam Kumar Apr 16 '15 at 11:59
  • Web page number 2 **needs** to be opened from the 1. one to get the link between them. If you create a new tab and go to page 2 directly, the first page does not know about it. – andeersg Apr 16 '15 at 12:04
  • Chrome has a page visibility API that will give you boolean on tab changes, currently visible and even prefetched status. – Ben Racicot Dec 08 '18 at 21:31