» Forums
» DynarchMenu forum
» Support
» Context menus on images
Context menus on images
2005/06/03 03:24
Viewed 5069 times
Replies: 2/2

This relates a little to my earlier post regarding namespace poisoning in Opera (only in that it's the same code). The example is now at http://tams.com.au/~mca/image_context_menus/img_context.htm .

The problem I'm having is getting a consistent interface across the 3 browsers that I care about (Opera, Firefox and IE). I have set it to activate on both left and right mouse buttons which works fine in FF but I can only get right click in Opera and left click in IE. I'd be happy to have only one button to activate the menu but I'd like it to be consistent if at all possible.

Is it possible to capture the right click event on an img tag in IE ? That seems to be the problem (i.e. I'm seeing the normal context menu that you see when clicking on an image)

Cheers,
Michael

Re: Context menus on images
2005/06/03 07:10
Viewed 6925 times
Replies: 0/0

adf

last
Re: Context menus on images
2005/06/03 07:23
Viewed 6818 times
Replies: 0/0

Bugger, sorry about that, what I meant to say was this...

I've done a little more playing around with very simple html/js tests to see what is going on. It looks to me that IE simply ignores any oncontextmenu trigger set on an area tag even though the MSDN site indicates that oncontextmenu is applicable to it. The other alternative is that it's not ignored but never actually gets to it (I'm thinking here that the img event is triggered before the area event and so never gets to the area).

Alas, I think I'm screwed with what I wanted to do. I had hoped to have the usual href tag on the area used to drill down to the "default" subgraph with a left click and then use the rigth click context menu to allow the user to select the subgraph they want. This works well in FF and Opera but fails miserably in IE due to the above limitation. The only other possibility I can think of is to somehow allow a modifier key to be used to trigger the menu. Unfortunately I think this would require a reasonably complex change the the dynarch menu code...

I just did some testing and a little hack to the code. In the definition of the ctx_onContextMenu event function you had the following
if(!is_opera||ev.button==2)

Now, this explains somthing else that's been bugging me. In opera you are using the onclick and onmousedown event to trap the left and right clicks when setting up the context menu and then calling the ctx_onContextMenu handler function, then in the handler you test to see if the button is the right button and then do nothing if it's not... which explains why the left click context menus don't work in Opera!

Getting back to my original topis though, I replaced that test above with this
if(ev.shiftKey)
This pretty much gives me what i was after in this particular instance, i.e. a left click does the normal action and a shift-left click gives me the context menu.

Obviously this quick hack is not the "right" way to do it as we don't necessrily want this behviour on all context menus. Is there some way to turn this into a more correct implemenatation that can be better controlled? Perhaps store something in the _msh_info2 object that defines what modifiers are required to trigger the menu?

Cheers,
Michael

last
Google