We help IT Professionals succeed at work.
Get Started

block right click menu?

minnirok asked
Last Modified: 2012-06-21

Two pretty simple questions:

1) I have a javascript function handler for right mouse clicks. I call this function when the user right clicks a control I have. I'd like to block the default browser context menu from appearing, so I did something like this:

    function onRightClickMyControl() {
        alert("you right clicked, blocking default context menu!");
        document.oncontextmenu = function(){return false};

Ok that works, but after it is called once, all subsequent right mouse clicks on the page still block the default context menu. I'd like to only block the menu when my handler is called, otherwise display the default context menu.

2) What do the javascript Def() and Undef() functions do? Are they just testing if the variable name passed has actually been defined/created yet?

Watch Question
Principal Systems Engineer
Top Expert 2005
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE