Link to home
Start Free TrialLog in
Avatar of mannycalaveras
mannycalaveras

asked on

Disable right-click menu without warning

I need a way to disable the showing of ie's or netscape's right-click menu when the user right-clicks. I need it so that it would also allow other showing when right-clicking.

The way I need it is that I got a script that pops a menu when someone right-clicks anywhere in the frame I definited. The problem is when right-clicking, the menu appears, but is hidden by the browser's right-click menu.

So I need a way to disable showing of the menu and only that, so my menu will show. The original script works wight left-click but this causes problems with links and personnaly I think it is better with right-click.
Avatar of brigmar
brigmar

It's my understanding that the only way IE will 'disable' the right click is by showing a javascript "alert() /  confirm() / prompt()" dialog.

I think you'll have to stick with the left click..

Brian
Avatar of Michel Plungjan
Brigmar is correct. Only Netscape will allow cancelling of the right-click and that does not work on links or in form fields
IE has an activeX menu that WILL override the right click, but that would not work in netscape...

Michel
Then I assume you _could_ combine the two... the IE activeX object with NS disable code inside (for a NS/IE disable).

Although... I think what is needed is for the click to then be passed to manny's own function.

Where's this activeX menu ?

Cheers,

Brian
Somewhere on msdn... I am sorry, but I do not have the url

Michel
ASKER CERTIFIED SOLUTION
Avatar of larholm
larholm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
THOR, GOD OF IE5-RIGHTCLICK!!!

Now make that work in IE4 and Netscape on links, formfields and images ;-)

Michel
hehe, god of thunder and now god of IE5-rightclick? cool ;)

In Netscape you don't have to display an alertbox to get it working, but you have to do this in ie 4 ;(

use the following:

<html>
<head>
<script language="Javascript">

function click(e) {
if (document.all) {
if (event.button == 2) {
alert(sorry);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
return false;
}
}
}


function cancelClick(){
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
if (!window.print){
document.onmousedown=click;
}
}

</script>
</head>
<body oncontextmenu="return false">

</body>
</html>

/Thor
Yes, we know
Except the return false and the document.capturevents is ignored on links and form elements!

Michel
If you want it too on links, formfields and images, add these lines

document.images.onmousedown=click;
document.links.onmousedown=click;
if (window.all){
document.all.tags["INPUT"].onmousedown=click;
}

right after

document.onmousedown=click;

/Thor
response would be nice, I wrote this out of my head ;)

/Thor
I will test this tomorrow!

Michel
Okay, but it should work correctly, even on links, images and form input fields ;)


However, IE 4 must have the alert box, but in my code I have disabled it if you're using NS 4 or IE 5.

/Thor