Click to See Complete Forum and Search --> : onclick and oncontextmenu
Cedric
12-15-2003, 02:15 AM
Hello,
I would like to know with which click of the mouse the user clicked on a onclick object. I must use only onclick and not oncontextmenu.
Do you have an idea?
Thank you.
Cedric
fredmv
12-15-2003, 02:17 AM
Do you mean which button the user used on the mouse?
Cedric
12-15-2003, 02:21 AM
Yes.
P.S :Sorry for my bad English
fredmv
12-15-2003, 02:31 AM
No problem — I just wanted to make sure I knew what you were looking for.<a href="#" onclick="alert('left-click');" oncontextmenu="alert('right-click');">foo</a>
Cedric
12-15-2003, 02:51 AM
Ok, thank you but that, I have do it already.
I should not use the ' oncontextmenu'. Just onclick.
For example a function 'action()' which calls the function f1() if it is the left button and a function f2() if it is the right button.
function action(f1, f2)
{
if [left button]
f1();
elseif [right button]
f2();
}
And in the body for a <div> for example :
<div onclick='action(f1, f2)'>foo</div>
Do you understand what I would like to do?
fredmv
12-15-2003, 03:00 AM
I used onmouseup so both events could be captured; onclick only catches left-clicks.<script type="text/javascript">
//<![CDATA[
function foo(what)
{
if(what == '0' || what == '1') function1();
if(what == '2') function2();
}
function function1() { alert('left'); }
function function2() { alert('right'); }
//]]>
</script><a href="#" onmouseup="foo((arguments[0]||event).button);">bla</a>
Cedric
12-15-2003, 03:10 AM
Ok, it is very well.
I will make like that.
Thank you very much.
Cédric
fredmv
12-15-2003, 03:12 AM
You're very welcome. :D