0

We have many hyperlinks in a html page. On click of which we do certain function.

After one hyperlink is clicked I wanted to make other hyperlink clicks to do nothing until first one finishes it processing. (During testing testers started clicking the hyperlinks rapidly one after another)

I did something like this, but it does not seem to be working. Basically used a variable to track if a hyperlink is clicked.

var hyperlinkClickInProcess=false;
function clickHandler(inputData){
     if(hyperlinkClickInProcess ==false){
        hyperlinkClickInProcess =true;
        linkProcessing(inputData);
        hyperlinkClickInProcess =false;
    }
}

Any thoughts on how to implement such functionality?

Vijay
  • 1

2 Answers2

0

This question tells how to use jquery to disable all the links on a page: jQuery disable a link. But instead of disabling just one specific link, you could use a similar strategy on all the links on the page by doing like so:

$('a').click(function(e) {
    if(hyperlinkClickInProcess) {
        e.preventDefault();
    }
    else {
        hyperlinkClickInProcess =true;
        linkProcessing(inputData);
        hyperlinkClickInProcess =false;
    }
});
Community
  • 1
  • 1
stevevls
  • 10,675
  • 1
  • 45
  • 50
0
function disableAllLinks() {

 // search for all links and remove onclick event handlers, + return false.

}

function enableAllLinks() {

 // search for all links and reassing onclick event handlers

}


function clickHandler(inputData){
   disableAllLinks();

   /// Link processing body here //// 

   enableAllLinks();
}
Scherbius.com
  • 3,396
  • 4
  • 24
  • 44