Is it possible to detect if a user has opened a link in a new tab?

后端 未结 7 1921
梦谈多话
梦谈多话 2020-11-27 15:33

If a user is on your website and opens another link (also to your website) in a new tab, is it possible to differentiate this from the user just clicking on the link normall

7条回答
  •  时光说笑
    2020-11-27 16:22

    You can sort of do it like this:

    if (history.length == 1) {  // Um, needs to be 0 for IE, 1 for Firefox
        // This is a new window or a new tab.
    }
    

    There may be other ways for history.length to be 1, but I don't know what they might be.

提交回复
热议问题