Click Logging with JavaScript

后端 未结 5 541
挽巷
挽巷 2021-01-03 01:55

I want to log all clicks on a link.

I\'ve written a little logger, which can be called by an url (returns an empty page). This url is called with a jquery-ajax-metho

5条回答
  •  抹茶落季
    2021-01-03 02:39

    The above poster is correct, it is unreliable because you are leaving the page before it has a chance to log it.

    You could do this:

    1) return false, so the href isn't active. 2) log the click 3) use location.href to redirect to the url it would have been redirected to

    you might see a slight delay if it takes long time for your onclick handler to execute.

提交回复
热议问题