About the onclick and ondblclick Event


I noticed. that if I write some code in the onclick && ondblclick. the onclick event will have a high priority to be trigger.

when I double click on the scheduler, the onclick event will always be triggered. scheduler can not distinguish them?


Hello @lypch ,

This behavior occurs because the browser generates both dbl-click and single click in case of dbl-click action, and the current scheduler implementation can’t avoid it.

If you want to have the code which will run on a real single click, you can use the following workaround:

var sin_timer = null;
function sin_click(event_id, native_event_object)
  if (sin_timer == null)
    sin_timer = window.setTimeout(real_onclick, 500 );
  return true;
function dbl_click(event_id, native_event_object)
  sin_timer = null;

  return true;
function real_onclick()
  alert("I'm called only for real single clicks");
  sin_timer = null;
scheduler.attachEvent("onDblClick", dbl_click)
scheduler.attachEvent("onClick", sin_click)

Here is demo:

AS you can see, the function real_onclick will run only after one single click.