September 25, 2007

OnContextmenu EventHandler

This event handler used to prevent context menus from displaying
The default context menu always displays when you right click on the webpage.
If you want to disable/Hide the menu that appears by right clicking the browser, this event handler is the best thing to use.

Here is the code :

In the body tag of the HTML page make sure that oncontextmenu returns false.
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" oncontextmenu = "return false" >

If you want the context menu to display only if you right click and also holding control key.This might be useful for devloping dubugging environments.

Here is the Code

Oncontectmenu = “return event.ctrlKey”

Good Luck!!

1 comment:

Deepak Vasudevan said...

That would be Internet Explorer specific. However, a quick DHTML snippet, a few of them are available in http://www.dynamicdrive.com/ should address Netscape and FireFox and across Windows/MAC and other platforms as well.