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();
)
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
I have solved this with the below code,
<a id="press" href="javascript:void(0)" onclick="singleClick(event)"
ondblclick="doubleClick(event)">Click here</a>
<div id="log"></div>
My JavaScript will be ,
var timer;
var status = 1;
function singleClick(event) {
status = 1;
timer = setTimeout(function() {
if (status == 1) {
document.getElementById("log").innerHTML ='I am single click !';
}
}, 500);
}
function doubleClick(event) {
clearTimeout(timer);
status = 0;
document.getElementById("log").innerHTML = 'I am a double click!';
}
Please let me know the status.Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With