[OpenLayers-Users] Right-click menu

Graham Davis gdavis at refractions.net
Wed Feb 21 15:54:07 EST 2007


Well, I seem to have found the answer to my own question, so I thought 
I'd email it to the list just in case anyone else needs to know how.

Basically there is an oncontextmenu event for DOM objects.  You can 
assign this to a function and put any code you like in there, and then 
return false at the end to ensure the event stops and doesn't display 
the browser's context menu.  So I added this to my map object to disable 
all browser context menus from appearing on the map like so:

map.div.oncontextmenu = function noContextMenu(e) {return false;};

Seems to work well in both IE and FF (haven't test Opera or on a Mac).

-- 
Graham Davis
Refractions Research Inc.
gdavis at refractions.net



Graham Davis wrote:

>I'm trying to implement a right-click menu on my map, similar to what 
>you see here: http://maps.ask.com/maps.  I've been able to properly 
>recongnize a right-click event in the MouseDefeaults.js file on mousedown.
>
>My problem is that the browser's own right-click menu also appears, and 
>I need to disable or stop this.  I've tried stopping the event from 
>propagating in the mousedown function after my code (and in the mouseup 
>function since that is when the browser menu seems to appear) however 
>this doesn't stop the browser menu from appearing.
>
>Has anyone been able to implement a right-click menu on their map that 
>properly disables the browser's right-click menu?
>
>Also, this might be of importance, but I'm using the vector branch of 
>code.  I've noticed that when not using a vector layer, the right-click 
>menu on the map brings up the image menu as you have clicked on an image 
>in the map.  When there is a vector layer overtop, right-clicking brings 
>up the standard browser menu where you can view source and whatnot, so 
>the menus are different.  However, I think any fix for this would work 
>for both (and I have been testing everything I try both with and without 
>a vector layer). So far nothing works.
>
>  
>





More information about the Users mailing list