Reputation: 319
Can anyone please tell me how can I detect if user has already opened the link/url tab and is it possible to redirect a link to a active browser tab if the url is already opened?
Eg: User clicks on the link and js code will open a new tab in browser.Now if user again clicks on the link I want him to redirect to the active session instead of opening a new tab.
I read the below post but unable to implement my logic according to them:
Java: ensure web application open only in one browser tab
Possible to detect if a user has multiple tabs of your site open?
I am using simple window.open(url) to open my url in new tab.
Thanks....
Upvotes: 2
Views: 7403
Reputation: 3905
use the target/window name in javascript do that
window.open(yoururl, youruniquewindowname)
example
window.open("https://stackoverflow.com/", "stack_unique_123")
if a window with stack_unique_123, is already open, the "https://stackoverflow.com/" will be reload in that window, preventing a new one to be open.
Upvotes: 0
Reputation: 1064
if you give a name to the opened window it will reopen the same the second time
window.open(url,"mypopup");
Upvotes: 4