Monday, December 18, 2006

Disabling the Browser Context Menu

You can disable the browser context menu for an element in your DOM with the following JavaScript recipe:

function disableContextMenu(element)
element.oncontextmenu = function()
{ return false; }

For example, to disable the context menu over a photo on your page, you could use:


Browsers like Firefox do not always allow web pages to disable the context menu (this option is a setting in Firefox), so this recipe will not work 100% of the time in all browsers.

See the example

No comments: