Solved

How do i detect right click event for onClick()?

Posted on 2002-04-28
9
1,870 Views
Last Modified: 2012-05-05
i have javascript code as follow..

<script language=javascript>
function assignGroup(){
     alert(event.button);
}
</script>

<FONT SIZE=1.8 FACE =ARIAL COLOR=#006043 onClick=displayMenu()>My Text</FONT>

my question is,when user click on My Text, how do i know either the user is using right click or left click?

from the code above.. i get 0 for event.button when i left click at the text button get nothing when i right click on the text..please guide...

thanks
0
Comment
Question by:pleasure
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 6974696
try onMouseUp instead of onClick.

CJ
0
 
LVL 10

Expert Comment

by:eyal_mt
ID: 6974701
IE has the oncontextmenu event which only occurs for right clicks so you can use it with a different funtion.
0
 

Author Comment

by:pleasure
ID: 6974712
CJ:
onMouseUp didn't give any response...:(

eyal_mt:
can you please explain more about your method.. i'm quite new in JavaScript..:p


thanks...
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 23

Expert Comment

by:b1xml2
ID: 6974713
<html>
<head>
<title>Click</title>
<script language="javascript">
function checkClick() {
 alert("Event Button - " + event.button + "\n" + (event.button == 1 ? "Main" : "Secondary") + " Button Clicked");
}
</script>
</head>
<body>
<font size="1.8" face="arial" color="#006043" onmouseup="checkClick()">my text</font>
<ol>
<li><b>Main Button Usually Refers To The Left Click And Returns A Value Of 1</b></li>
<li><b>Other Buttons Return Values Other Than 1</b></li>
</ol>
</body>
</html>
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6974714
Works for MSIE4+
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 6974722
as per CJ_S suggestion =). So, CJ_S should get credit for this.
0
 
LVL 10

Accepted Solution

by:
eyal_mt earned 50 total points
ID: 6974726
use:

<FONT SIZE=1.8 FACE =ARIAL COLOR=#006043 oncontextmenu=displayMenu()>My Text</FONT>

instead of onclick
your displayMenu function will only be called when the user right click on your tag.

to prevent the original popup menu from IE use:
event.returnValue=false;

inside your displayMenu function
0
 

Author Comment

by:pleasure
ID: 6975199
yupe.. oncontextmenu() works...:) thanks...

menuPopup = window.createPopup();
menuPopup.show(menuXPos, menuYPos, iWidth, iHeight, document.body);

i used code above to popup my menu, is there any way for me to set my background color of my popup menu? Currently it's showing with color.

0
 

Author Comment

by:pleasure
ID: 6976023
actually..both of the solution work..but since i'm using eyal_mt solution so i think it's better for me to reward him/her..thanks a lot to all of you...:)
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question