admin管理员组文章数量:1391008
I have noticed when user clicks on a link with, say middle button, or shift/ctrl+left button, click handler attached to hyperlink is not called.
I have seen solutions to track mousedown event, but what I'd like is to track exact event of following a link.
Are there any suggestions? Thanks
I have noticed when user clicks on a link with, say middle button, or shift/ctrl+left button, click handler attached to hyperlink is not called.
I have seen solutions to track mousedown event, but what I'd like is to track exact event of following a link.
Are there any suggestions? Thanks
Share Improve this question asked Apr 5, 2010 at 11:26 glaz666glaz666 8,74119 gold badges58 silver badges75 bronze badges4 Answers
Reset to default 3mousedown
/mouseup
is indeed the only way you can get notified of middle button interaction, so detecting a down-then-up event without intervening mouseout
event is more or less the best you can do. It's not very good.
I wouldn't bother, since even if you trapped this one eventuality, there are many other interactions you can't pick up. As well as middle-click (which might not be ‘Open in new tab’ in all browser/configurations; for example in IE6 that'll be the user turning on scrolling mode), the user might right-click and ‘Open in new window’, or drag the link to the address bar or new tab, or various other browser-specific actions to perform a navigation.
If the link is on your site then track it when the page loads instead of on the page where they get the link. If the link is to another site you need to use a redirect URL so your site can track it (example: http://yoursite./redirect.html?redirect=http://othersite.
).
In the redirect page you might do something like this (if you want to use JavaScript):
$(document).ready(function(){
//insert your tracking code here...
var redirect = getParameterByName('redirect');
if(redirect != ''){
window.location = redirect;
}
});
// From https://stackoverflow./questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144
function getParameterByName( name ){
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
you can use 'mousedown' 'mouseup' events in bination with "event.which".
example: http://jsbin./ikahe/edit
How to do click hijack right... or rather left.
https://web.archive/web/20160305021055/http://mislav/2011/03/click-hijack/
本文标签: javascriptjQuery click handler is not invoked when link is opened in new tabwindowStack Overflow
版权声明:本文标题:javascript - jQuery: click handler is not invoked when link is opened in new tabwindow - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744585589a2614177.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论