rubo77 rubo77 - 1 year ago 88
HTML Question

Call ondblclick without calling onclick-event

Is there a simple solution without jquery, inside HTML-tags, that will call the

ondblclick
without causing
onclick
to happen too?

This always closes the window although it should just show the alert:

<a href="#" ondblclick="alert('dbl')" onclick="window.close();">X</a>


(it only works in a javascript popup, cause you cannot close the main window with
window.close();
)

Answer Source

My guess is that every solution will also have the problem with the doubleclick timeout-length varying on user preferences described by Irvin Dominin aka Edward in the comment above:

From jQuery docs but related: "It is inadvisable to bind handlers to both the click and dblclick events for the same element. The sequence of events triggered varies from browser to browser, with some receiving two click events before the dblclick and others only one. Double-click sensitivity (maximum time between clicks that is detected as a double click) can vary by operating system and browser, and is often user-configurable."

I abandoned using doubleclick and used CTRL+click instead:

<a href="#" onclick="if(event.ctrlKey) { 
 alert('CTRL+Mouseclick'); return false; 
} else { window.close(); }">X</a>

see:

Catch onclick-event with CTRL pressed

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download