View Full Version : image link - using both onClick & onDblClick

07-08-2006, 08:22 PM
Hi there,

I'm trying to get one image to serve as two links, depending on the type of event handler that's used. If a user clicks once with their mouse, webpage1 should load in an iframe called EC Content. (EC = event calendar). Likewise, if a user double clicks, webpage2 should load into EC Content.

The result of my simple efforts is that href is processed wonderfully by IE, NS, and Mozilla Firefox, but onDblClick won't work in any of the three browers.

I used this approach:
<a href="next_meeting.htm" target="EC Content" onDblClick="parent.frames['EC Content'].location='bottom.htm';"><img src="calendar_mainpage.jpg"></a>

I suspect the problem is linked to the hierarchy of event handlers, which has href/onClick evaluated before onDblClick, and of course, the fact that onDblClick calls onClick into action, making things worse.

I found javascript code that separates the two actions (with a delaying technique), but I'm failing to correctly replace the alert function with code that will have webpage1 and webpage2 load into the correct iframe (EC Content).

Here's a link to the javascript code: http://www.webxpertz.net/forums/showthread.php?threadid=2188

*look towards the bottom and you'll see it.

I've tried: self.document.location.href="webpage2.htm"; which works, but since it doesn't encompass the name of the iframe I want to target, webpage2.htm does not load into the right iframe. The word "self" is messing things up.

I'm not experienced at writing Javascript, although I've looked at a lot of it. lol. Does anyone have a suggestion?

07-08-2006, 08:36 PM
I figured it out. I'm so silly sometimes.

This is the code I eventually came to:
frames['EC Content'].document.location.href="webpage2.htm";

When you replace the alert function with it, the javascript works like a charm.

07-08-2006, 08:41 PM
If you add return false to it, like:
onDblClick="function(); return false;"

the link won't load.... as it is now, you're likely loading the href, then the dblclick link. So... it works, but you wouldn't really want to load the href first.

07-08-2006, 09:37 PM
I'd suggest:
<a href="next_meeting.htm" target="EC Content" onclick="return false;" ondblclick="parent.frames['EC Content'].location='bottom.htm';return false;"><img src="calendar_mainpage.jpg"></a>That should cause the least confusion.