/    Sign up×
Community /Pin to ProfileBookmark

ondblclik on img

I tried to put both an ‘onclick’ and an ‘ondblclick’ on an img tag. Problem, JS doesn’t leave me time for the secund click, however fast I click ! It always immediately handles the ‘onclick’ condition. Yet I use double-clicks all the time on my PC without problems.

So that was the first question.

So, as I got nowhere with the ondblclick, I decided to use both left and right click. This time IE understands the difference (in Netscape, it’s no hope, it works a completely different way) and handles correctly both events. But, problem, after the right click has been handled, the context window opens anyway… I don’t want that.

So, that was the secund question.

And now for the summarizing third question:

The real problem is: I want to be able to launch two different actions relative to the same image, be it by click, dblclick, right or left click, or by shooting at the screen with a Smith&Wesson.

What is the right strategy ?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@PittimannFeb 06.2005 — Hi!

Why don't you put a little delay on the onclick?

In a script tag:

var timer;

The image tag:

<img src="whatever.gif" alt="&nbsp;&nbsp;" ondblclick="clearTimeout(timer);alert('double')" onclick="timer=setTimeout('alert('single')',300)">

Cheers - Pit
Copy linkTweet thisAlerts:
@herodote92authorFeb 06.2005 — Well, I had a hell of a time with the single and double quotes (because the code is built with JS), and the result is the same. If you doubleclick, it just makes the alert window "single" flash, and that's it. No "double" in sight.
Copy linkTweet thisAlerts:
@herodote92authorFeb 06.2005 — No, wait ! Seems there was a syntax error again somewhere. I actually SAW "double" on my screen, although I didn't quite understood was was happening. I'll test further.
Copy linkTweet thisAlerts:
@herodote92authorFeb 06.2005 — Aaaaaaaaarrrrgghhhh I GOT the whole f...ing darned thing. Here is what it looks like:
<i>
</i> champ = "&lt;img id='E"+ient+"' name='S"+isor+"' src='"+src_symb+"'";
champ += " title='Clic gauche: [Dé]PliernClic droit: [Dé]Sélectionner'";
champ += " ondblclick='clearTimeout(timer);Clic(this.name,this.id,2);'";
champ += " onclick='top.a=this.id;top.b=this.name;timer=setTimeout(";
champ += '"Clic(top.a,top.b,1)"';
champ += ",300)'&gt;";
row.insertCell(niv).innerHTML = champ;
tbodyresult.rows[isor].cells[niv].className = "tdsymb";
row.insertCell(niv+1).appendChild(docresult.createTextNode(wcode+" "+descript));


Oh well, a child could have found it out easily.? ? ?

Thanks for help anyway, since I'm no more a child, alas.
×

Success!

Help @herodote92 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...