How to prevent users form double clicking

ces123

Honorable
Dec 28, 2012
1
0
10,510
0
My clients are used to double clicking even if they are not supposed to. I want to tweak the java script to dynamically disable links/buttons after a click. But how? i don't know an iota about java script.
 

randomizer

Distinguished
Moderator
Jul 24, 2006
880
0
19,260
62
It's amazing what years of clicking desktop icons will do to people :)

This should work in most browsers, although I haven't actually tested it in much. It will "disable" all links, buttons and inputs that are of the button or submit type (mostly for forms) when clicked. It shouldn't interfere with anything else that happens when you click the buttons on your site, but if your links do anything other than navigate to another page this will break the extra functionality.

Note that it also requires that you have the JavaScript library jQuery available. You can also achieve similar functionality without external libraries with a bit more effort (I actually had some code here earlier, but it wasn't very good so I removed it).

JavaScript:
(function ($) {
    $(document).on('click', 'button,input[type="button"],input[type="submit"]', function () {
        this.disabled = true;
    });

    $(document).on('click', 'a', function (e) {
        window.location.href = this.href;
        this.href = '#';
    });
}(jQuery));
This can go in a script tag at the bottom of the page (right before the body) or, preferably, in a separate JavaScript file that you can include with a script tag inside the document's head tag. You may already have one you can put it in.

Are you able to involve the developer who built the website in the first place, or someone else with web development skills? They're in a better position to make these sorts of changes because just copying and pasting code when you don't know an iota of JavaScript is potentially quite dangerous. After all, you may not want to disable all links and buttons.
 
Thread starter Similar threads Forum Replies Date
C Apps General Discussion 1
A Apps General Discussion 8
G Apps General Discussion 0
O Apps General Discussion 4
J Apps General Discussion 9
S Apps General Discussion 9
R Apps General Discussion 11
E Apps General Discussion 3
C Apps General Discussion 4
Can You Help Me Please Apps General Discussion 3
eodeo Apps General Discussion 2
K Apps General Discussion 3
R Apps General Discussion 0
A Apps General Discussion 0
5 Apps General Discussion 1
Hastibe Apps General Discussion 11
J Apps General Discussion 1
K Apps General Discussion 0
T Apps General Discussion 6
A Apps General Discussion 1

ASK THE COMMUNITY