Created
January 28, 2015 22:06
-
-
Save pangui/86b5e0610b53ddf28f94 to your computer and use it in GitHub Desktop.
Prevent double click!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery plugin to prevent double click | |
jQuery.fn.preventDoubleClick = function() { | |
$(this).on('click', function(e){ | |
var $el = $(this); | |
if($el.data('clicked')){ | |
// Previously clicked, stop actions | |
e.preventDefault(); | |
e.stopPropagation(); | |
}else{ | |
// Mark to ignore next click | |
$el.data('clicked', true); | |
// Unmark after 1 second | |
window.setTimeout(function(){ | |
$el.removeData('clicked'); | |
}, 1000) | |
} | |
}); | |
return this; | |
}; |
I could give an example.
On a website I'm building, we hit a problem where if the user clicked on a tab too much to refresh it, sometimes a list would post twice due to ajax calls. Implementing a double click check would control for that so it doesn't happen again.
How we can use it ? exampe please
@RabkinAlex With the code above, and this:
$('*').preventDoubleClick();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How we can use it ? exampe please