Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display classic menu

Status
Not open for further replies.

crazyBanana

Programmer
Joined
Jul 18, 2013
Messages
1
Location
FR
Hi all,

I had already developed the js code that allowed me to display the context menu through another action. For example, by left clicking or pressing a key.
I managed to do what I wanted for most elements except for some like the mails in gmail or hotmail. When you right-click, there is a small menu with "archive" or "mark as unread" for example. It's not the classic menu which appears.
What I would like to do is force the display of the classic menu on these too.
Here is the code I have so far to generate my contextmenu event :

JavaScript:
window.document.addEventListener("click", associate, false);
window.document.addEventListener("mousedown", associate, false);
window.document.addEventListener("mouseup", associate, false);

var associate = function(event)
{
    var element = event.srcElement||event.target;
    element.addEventListener("click", context, true);
    element.addEventListener("mousedown", context, true);
    element.addEventListener("mouseup", context, true);
};

var context = function(event)
{
    if(event.button == 0)
    {
        var element = event.srcElement||event.target;
        menu(element, event);
        event.stopPropagation();
        event.preventDefault();
    }
};

var menu = function(element, event)
{
    var evt = element.ownerDocument.createEvent('MouseEvents');
    var RIGHT_CLICK_BUTTON_CODE = 2;
    evt.initMouseEvent('contextmenu', true, true, element.ownerDocument.defaultView, 1, event.screenX, event.screenY, event.clientX, event.clientY, false, false, false, false, RIGHT_CLICK_BUTTON_CODE, null);
    element.dispatchEvent(evt);
};
With that, on an email in gmail for example I still have the special gmail context menu when I left click.
Do you have any idea about how I could do ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top