views:

1764

answers:

2

Does any one tried to successfully hide the context menu at blur event? What I want to do is to hide the customized right click menu when the mouse is not positioned inside the context menu div.

This uses the jquery context menu plugin.

A: 

Use blur with a callback. It is not tested though. Do you want to restore the right click functionality on other blur? I think this will be better executed on other types of events.

$("input").blur(function () {
     window.oncontextmenu = function () {
        return false;
     }
});
Elzo Valugi
While I realize he is literally asking for "onblur", what he describes isn't really a blur event.
TM
so you should downvote him, not me
Elzo Valugi
@Elzo People who are asking questions shouldn't be downvoted because they don't have a perfect understanding of what they are asking. If they did, they probably wouldn't need to ask a question in the first place. However, giving an answer with wrong information is different. I downvoted because I felt that this answer was wrong, and clearly didn't make much effort to actually read the question (only the title)
TM
This is not way to stimulate me to give a better answer. Think that we are not all native English speakers and context menu could be a misleading notion. I understand now what he wants.
Elzo Valugi
the custom context menu from this plugin doesnt have a container?
Elzo Valugi
A: 

You mention the blur event explicitly, but I don't think that's actually what you need, since the context menu div you mentioned probably will not ever be focused or blurred.

You should use the mouseout event:

Assuming your context menu has an id of 'contextMenuContainer', this should cover it:

$('#contextMenuContainer').mouseout(function() {
    $(this).hide();
});

For more see the jQuery Events/mouseout documentation.

Update:

I tried registering a mouseout event handler on the plugin page you linked to, and it was firing just fine. I should note that it fires every time you change menu items though, so you'll need to check the event target to make sure the mouse has actually exited the entire menu.

TM
I tried to use the mouseout but seems the event isn't triggered. What could possibly go wrong?
kratz
It could be that some other event is firing on mouseout and the event handler stops the event from propagating. Could you be more specific about which plugin you are using? I can find multiple "jquery context menu plugins".
TM
I am using plugin coming from this link. http://www.trendskitchens.co.nz/jquery/contextmenu/How can I resolve event propagation?
kratz
I see you marked it as accepted, were you able to resolve the issue?
TM
not yet. still looking for the solution.
kratz