javascript - How to prevent users from clicking multiple times on a linked image? -


i have page linked image, link takes bit of time load. therefore, users tend click multiple times on it. causes errors crop in code. how prevent users clicking on link more once?

in attempt remedy this, changed link onclick event , in function used code:

$('#myimageid').unbind('click'); window.location.href = "mylink"; 

however, doesn't seem helping. also, i'd prefer keep simple linked image instead of using javascript.

once solution add class element used flag determine of code should run.

here's example: http://jsfiddle.net/qlhr8/

$('#myimageid').click(function() {    var $th = $(this);    if( !$th.hasclass( "pending" ) ) {            // add "pending" class, subsequent clicks not            //   run code inside if()        $th.addclass( "pending" );        window.location.href = "mylink";        // settimeout remove class        //   if new page never loads    } }); 

with added class, can change of image (lower opacity perhaps) indicate shouldn't clicked again.

.pending {     opacity: .4;     filter:alpha(opacity:40);     cursor: wait; } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -