Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Thanked 0 Times in 0 Posts

    Bullet-proof Jquery implementation: Capturing click interactions without fail

    Hi, I'm new to this forum and JS coding in general (learner stage!).

    I am using Jquery to fire events when users interact with different elements (primarily click interactions). My concern (due to ignorance probably) is that Jquery can't/wont always work to capture the interaction so my goal is to make minimise that potential failure rate (and learn about when such occurances may happen).

    I've already identified a few complications:

    - element being clicked on has/doesn't have target _blank attribute so delay is necessary
    - people open link in new tab by using Ctrl+Click, right click then "Open in new tab", clicking middle buttons for mouses with custom configuration
    - element is an email address (I've had the code below end up opening the link twice)

    Assuming there are NO JS errors in the code, are there any other situations where the Jquery might not capture the click event? Any browser/device specific situations?

    See my code below for my efforts so far

     // Clicked Social Profile
        if ($(this).attr('target').toLowerCase() == '_blank' || e.metaKey || e.ctrlKey || e.which == 2 || e.which == 3) {
          var newtab = true;
        if (!newtab) {
          setTimeout('location.href = "' + this.href  + '"', 150);
    Many thanks for your help!

  2. #2
    New Coder
    Join Date
    Nov 2010
    Thanked 3 Times in 3 Posts
    Possible complications with iOS devices, may want to have a conditional you can use?
    clickOrTouch: (detectIosDevice()) ? 'touchstart' : 'click',
    you'd make your own function to detect if a touch device is being used and just call it where 'detectIosDevice" is. I've had analytic issues before with just click. it would actually fire 2x on 'touchstart' and on 'touchend'


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts