How do I detect what object or ID or the user right-clicked on? I'm using the onContextMenu to trigger a function but I don't know how to detect the target.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Your handler should accept an event object as its parameter; the srcElement property of the event will be the object that triggered the event.
PS. I've seen similar code before ;)
As Patrick mentioned, you are receiving an event object as parameter to your onContentMenu callback function, where you can find the element triggered the event. I am using this code for cross-browser compatibility.
Note: originalTarget is Mozilla specific. You might want to pay attention to event.target https://developer.mozilla.org/en/DOM/event.target