Created
October 16, 2012 08:13
-
-
Save conanite/3897979 to your computer and use it in GitHub Desktop.
Prevent users double-clicking links and form submit buttons and anything else
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
$("input[type='submit']").one_click_only(); | |
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
(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