Skip to content

Instantly share code, notes, and snippets.

@conanite
Created October 16, 2012 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanite/3897979 to your computer and use it in GitHub Desktop.
Save conanite/3897979 to your computer and use it in GitHub Desktop.
Prevent users double-clicking links and form submit buttons and anything else
$("input[type='submit']").one_click_only();
(function($) {
$.fn.one_click_only = function() {
this.click(function(event) {
var now = new Date();
var previous_click = $(this).data("clicked");
if (now - previous_click < 500) {
event.preventDefault();
}
$(this).data("clicked", now);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment