Javascript 使用Jquery.click()我还能捕捉到在新选项卡或窗口中打开的内容吗?

Javascript 使用Jquery.click()我还能捕捉到在新选项卡或窗口中打开的内容吗?,javascript,jquery,onclick,Javascript,Jquery,Onclick,让这变得简单。我有一些文字,当你点击它。然后它会将您重定向到home.html 详情如下: $('#ElementID').click(function () { $('#ElementID').html('Redirecting...'); parent.location = 'http://' + host + '/home.html'; window.location = 'http://' + host + '/home.html'; })

让这变得简单。我有一些文字,当你点击它。然后它会将您重定向到home.html

详情如下:

$('#ElementID').click(function () {
        $('#ElementID').html('Redirecting...');
        parent.location = 'http://' + host + '/home.html';
        window.location = 'http://' + host + '/home.html';
});
<a href="home.html" id="ElementID">Redirect!</a>
实际链接如下:

$('#ElementID').click(function () {
        $('#ElementID').html('Redirecting...');
        parent.location = 'http://' + host + '/home.html';
        window.location = 'http://' + host + '/home.html';
});
<a href="home.html" id="ElementID">Redirect!</a>

例如:

如果右键单击上面的
你看到你得到了“在新标签中打开链接”/“在新窗口中打开链接”现在我能捕捉到这一点并触发重定向(在当前窗口上)当他们使用这些选项之一时,而不仅仅是直接点击

现在请注意,Jquery.click()还捕获了对元素的单击。 我可以使用类似于catch“在新选项卡中打开链接”/“在新窗口中打开链接”

的方法吗?您可以添加一个
blur()
处理程序,以便当用户离开页面时(通过单击另一个选项卡,或者在单击后失去对注销按钮的关注),它将重定向:

$('#logout').blur(function (){
    parent.location = 'http://' + host+ '/home';
    window.location = 'http://' + host+ '/home';
});

这将是一个很好的解决方案,但我需要能够有多个标签打开和工作,你可以有很多标签打开你想要的。只是,如果您单击注销按钮(左键单击或右键单击),然后单击其他位置,则会发生重定向。如果您右键单击注销链接并选择“在新选项卡中打开”,然后单击新选项卡,然后返回到您单击注销链接的选项卡,它应该已重新定向到/主页。