Struts2 jQuery plugin: trigger link on double click
-
19-09-2019 - |
Question
I would like links to be trigger on double click. Something simple like this:
<sj:a href="%{link}" targets="target" ondblclick="javascript: return true;" onclick="javascript: return false;">Bližnjica</sj:a>
does not work (I guess because this is not a submit).
Maybe some JS can do that?
Solution
In jQuery it's easier with an ID, but you can bind to any <a>
as well:
$("a").bind("dblclick", function(){
alert("Double Clicked");
}).click(function() {
return false; //Prevent single click
});
However, if you want a double click, I'd suggest using an element other than <a>
for this, like a <span>
or <div>
Then it's much simpler like this:
$("#myDiv").bind("dblclick", function(){
alert("Double Clicked");
//Go to some link, etc, whatever you want
//Example, going to a link on double-click:
//window.location = $(this).attr("href");
});
And the markup side:
<sj:div id="myDiv" href="%{link}">Bližnjica</sj:div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow