Development onContextMenu() block context menu?

Discussion in 'Software' started by OneSeventeen, 13 Apr 2005.

  1. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    I am using onContextMenu() for a few functions, and I'd rather disable the standard context menu to replace it with my own.

    Right now I have it just alert("does this work?");, so when I right-click on an item, it popus up a box that says "does this work?" then when I click OK, the normal context-menu appears.

    Is there a way to stop the normal context-menu from appearing?
     
  2. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    Okay, so I've figured it out...
    onContextMenu="javascript:mycoolfunction('some variable');return(false);"

    Seems to work great, but now I want my own window to pop up. Is there a way to get the x and y coordinates of the mouse during the right click so I can have it display a <div> or something with my features in it right next to the link?
     
  3. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
  4. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    Now, do I need to always be recording the x and y coordinates of the mouse, or can I just get them when I click somewhere? I'm not quite qure what the function is doing...
     
  5. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    Rough and dirty; not checked in any way, shape, or form - nor (if it did work) is it cross browser compliant.

    Code:
    #divMenu {
      background-color: #CCC;
      display: none;
    }
    
    
    <div oncontextmenu="showMenu();">right click me</div>
    <div id="divMenu">menu guff</div>
    
    
    showMenu() {
      objMenu = document.getElementById('divMenu');
      objMenu.top = window.event.y;
      objMenu.left = window.event.x;
      objMenu.style.display = 'block';
    }
    
    Something like that. :)

    You also need some code to get rid of the menu if you a) click on it and b) click away from it.
     
  6. Hwulex

    Hwulex What's a Dremel?

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    Sorted on MSN. :)


    For anyone that's interested, here's a simple - though not necessarily the best (although it is cross browser compliant) - example:
    .
     

    Attached Files:

    • menu.zip
      File size:
      869 bytes
      Views:
      3

Share This Page