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

Posted on 2002-04-28
Medium Priority
Last Modified: 2012-05-05
i have javascript code as follow..

<script language=javascript>
function assignGroup(){

<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...

Question by:pleasure
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
LVL 22

Expert Comment

ID: 6974696
try onMouseUp instead of onClick.

LVL 10

Expert Comment

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

Author Comment

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

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

LVL 23

Expert Comment

ID: 6974713
<script language="javascript">
function checkClick() {
 alert("Event Button - " + event.button + "\n" + (event.button == 1 ? "Main" : "Secondary") + " Button Clicked");
<font size="1.8" face="arial" color="#006043" onmouseup="checkClick()">my text</font>
<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>
LVL 23

Expert Comment

ID: 6974714
Works for MSIE4+
LVL 23

Expert Comment

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

Accepted Solution

eyal_mt earned 200 total points
ID: 6974726

<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:

inside your displayMenu function

Author Comment

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.


Author Comment

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...:)

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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'…
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…
Suggested Courses

770 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