Code for right click event

Discussion in 'JavaScript' started by James McMurray, Dec 3, 2007.

  1. #1
    Yes, I know it's frowned upon. Yes, I know the world is safer if neophyte coders aren't allowed these atrocities. And yes, I know it won't work in some browsers.

    But I still want to do it. :)

    I've got some code that works great onclick. However, it's set up to change an input box's background color, so running it onclick is not going to work. I can do it on control click, but eventually I'll be adding other right click options to the app, so would like to consolidate them all under one roof so-to-speak.

    Can someone please post or point me to a snippet that will check for a right click and disable the browser's right click menu if possible?

    Thanks,
    James
     
    James McMurray, Dec 3, 2007 IP
  2. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #2
    sharry, Dec 3, 2007 IP
  3. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks! That had the oncontextmenu stuff I was missing. Everything's running great now!

    Here's what I'm using it for (it's actually going into a bigger app, but that's the test file I used). Right click on any of the input boxes labelled "name" and you can change it's background color. It's for this, so people can sort the counters more easily.
     
    James McMurray, Dec 3, 2007 IP
  4. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #4
    amazing stuff nice work :)
     
    sharry, Dec 5, 2007 IP
  5. James McMurray

    James McMurray Peon

    Messages:
    52
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks, although most of the color picker is someone else's work. I just changed the color array and told it to work on the background color of the target instead of changing the text in a hidden input box like the original did.
     
    James McMurray, Dec 5, 2007 IP