Is there any way that I can keep all the hover effects but trigger the tag link (to another page) only when double clicking? Thanks!
Any pure javascript answer? (no jQuery)
Is there any way that I can keep all the hover effects but trigger the tag link (to another page) only when double clicking? Thanks!
Any pure javascript answer? (no jQuery)
I would of course won't go against one click standard, but if that's what you wish:
You can find an answer to that here
Copying from the answer above:
HTML:
<a id='golink' href='gosomewhere.html'>Go Somewhere</a>
JavaScript using jQuery:
jQuery(function($) {
$('#golink').click(function() {
return false;
}).dblclick(function() {
window.location = this.href;
return false;
}).keydown(function(event) {
switch (event.which) {
case 13: // Enter
case 32: // Space
window.location = this.href;
return false;
}
});
});
I came with this (without jQuery, using only an onclick event handler):
var clicked=false;
var el = document.getElementById('link');
var maxClicksDelay = 500; // in milliseconds
el.onclick = function(e) {
if(!clicked) {
clicked = true;
setTimeout(function() { clicked = false}, maxClicksDelay );
e.preventDefault();
}
}
I would suggest to add an attribute to handle links with a double click option.
<a href='http://...' dblclick>Link</a>
^^^^^^^^
At the end of your html document add this lines to find anchors with a specific 'dblclick' attribute:
<script type='text/javascript'>
$(function(){
$('a[dblclick]').click(function(e){
return false; // disable single click
}).dblclick(function(e){
window.location = this.href; // on double click go to the URL from href value
})
})
</script>