link

JQuery.on ('follow') event?

What is the appropriate way to follow link event?

<a href="#" class="link">link</a>
<script>$('.link').on('click', function() { });</script>

Capturing a click event is not enough, because you can follow the link by double-clicking or pressing the enter key.

Instead of wrapping every possible event, is there a ready-made function, for example on('follow')?

+4
source share
1 answer

You can solve your problem using semaphore. semaphoreshould go green after a certain time, say 100 milliseconds. Suppose you have a function like this:

function onFollow(params) {
    //do something
}

Suppose further that you have initialization, for example

var semaphore = true;
var time = 100; //for example

You need to have functionas follows:

function invalidEvent(e) {
    semaphore = false;
    setTimeout(function() {
        semaphore = true;
    }, time);
}

Let's have something like this:

$('.link').on('click', function(e) {
    //initialize params and maybe call e.preventDefault
    setTimeout(function() {
        if (semaphore) {
            onFollow(params);
        }
    }, time);
});
0

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


All Articles