Question

I'm trying to expand navigation options of the context menu on certain elements (specifically, h1 and h2 tags) I want to prevent the browser's default action when right-clicking on those elements.

I found nice information at this page.

However, I couldn't find how to disable the context menu for certain elements. Does someone know how to do it?

I'm using prototype as my javascript API.

Was it helpful?

Solution

This will prevent the context menu from appearing on a particular element

$(it).observe("contextmenu", function(e){
    e.stop();
});

So, for example stop all H1/H2 tags from showing a context menu

$$('h1, h2').each(function(it){
    $(it).observe("contextmenu", function(e){
        e.stop();
    });
})

OTHER TIPS

You can obfuscate it a bit, but ultimately your page is only a guest in the browser in, (and you can take that to mean in the same manner that a prisoner is a "guest" of the state, if you wish). Therefore the page must rely on the browser to play nice. If the user wants to run a browser that doesn't play nice, or customize their existing browser to do so, that is always their option. You can never force a browser to do anything. Nothing you can do will be able to stop the user from performing a given activity with their browser if they really want to, once they view a page on their local machine. More than that, most recent browsers have facilities already built in to make it very easy for the user to override the normal behavior when something seems out of the ordinary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top