0

Please see below code... Aims of the code is to display a floating menu on right clicking the screen and the menu should hide on left clicking the screen. The below works perfectly with IE and Chrome, but fails in firefox. I tried debugging with firebug, no positives at all.

$(document).ready(function () {
    document.onmousedown = onMouseClick;
}

function onMouseDown(ev) {

    document.oncontextmenu = onClickRightMouseButton; //to hide default menu on right click

    if (ev.which == 1) {
        console.log('1');
    }

    if (ev.which == 2) {
        console.log('2');
    }

    if (ev.which == 3) {
        var xPos = ev.clientX;
        var yPos = ev.clientY;

        document.onmousedown = onMouseClick;
        showFloatingMenu(xPos, yPos);
    }

    function onMouseClick(e) {
        if (e.which == 1) {
            if (!(e.clientX >= xPos && e.clientX <= (xPos + 200) && e.clientY >= yPos && e.clientY <= (yPos + 50))) { //50x200 is the floating menu diamension
                hideFloatingMenu();
            }
        }
    }

}
}
6
  • Why do you not set the oncontextmenu until after a click? And where are onMouseClick and onClickRightMouseButton? You tagged this jQuery, where is the jQuery?
    – mplungjan
    Commented Sep 1, 2013 at 4:56
  • When do you assign onMouseDown? I see document.onmousedown = onMouseClick and I see function onMouseDown(ev)
    – mplungjan
    Commented Sep 1, 2013 at 5:00
  • @mplungjan I am planning to add few options like add/delete on the context menu on right click. Once left mouse button is clicked (out side menu), it should hide. I'm using onmousedown instead on onmouseclick.. Does that having any issues? I am using jquery to attach the onMouseClick event to document on loading. Btw.. I am new to UI programming, these cross browser thinks looks confusing..
    – ram_c
    Commented Sep 1, 2013 at 5:01
  • @mplungjan There are two onMouseClick functions, one inside onMouseDown and and other outside, this stuff works perfectly with IE and Chrome!
    – ram_c
    Commented Sep 1, 2013 at 5:02
  • Be consistent and use jQuery's normalising of events so $(document).on("mousedown",function(e) {...}) and so on. Also install firebug and hit F12 perhaps there are errors in the console
    – mplungjan
    Commented Sep 1, 2013 at 5:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.