How to detect if user has already opened an url and redirect to same if already opened?

ぐ巨炮叔叔 提交于 2019-12-11 04:39:22

问题


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....


回答1:


if you give a name to the opened window it will reopen the same the second time

    window.open(url,"mypopup");



回答2:


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.



来源:https://stackoverflow.com/questions/17346114/how-to-detect-if-user-has-already-opened-an-url-and-redirect-to-same-if-already

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!