JQuery: click handler does not start when opening a link in a new tab / window

I noticed when a user clicks on a link with, for example, the middle button or shift / ctrl + left button, the clicker attached to the hyperlink is not called.

I have seen mousedown event tracking solutions, but I would like to track the exact event after the link.

Are there any suggestions? Thanks

+4
source share
4 answers

mousedown / mouseup is the only way to get notification of middle button interactions, so detecting a down-down event without an intermediate mouseout event mouseout more or less the best you can do. It's not very good.

I would not worry, because even if you are trapped in this possibility, there are many other interactions that you cannot pick up. As well as the middle click (which may not be β€œOpen on a new tab in all browsers / configurations, for example, in IE6, which will be enabled by the user in scroll mode), the user can right-click andβ€œ Open in a new window ”, or drag the link to the address bar or a new tab or other other browser-related actions to navigate.

+3
source

If the link is on your site, track it when the page loads, and not on the page where they receive the link. If the link is to another site, you need to use the redirect URL so your site can track it (for example: http://yoursite.com/redirect.html?redirect=http://othersite.com ).

On the redirect page, you can 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 http://stackoverflow.com/questions/901115/get-querystring-with-jquery/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]; } 
+2
source

you can use the mousedown mouseup events in conjunction with the event.which.

example: http://jsbin.com/ikahe/edit

+1
source

How to right-click or rather leave.

http://mislav.uniqpath.com/2011/03/click-hijack/

0
source

Source: https://habr.com/ru/post/1306020/


All Articles