Capture right-click event?

R

Robert Oschler

Hello,

In my web pages I attach the OnClick event. However this doesn't seem to
intercept right-click events. Is there another event I need to attach or is
it something else?

thx
 
B

Brynn

I know how to do it .. but I don't agree with the practice or ability
of it.
sorry,

Brynn


Hello,

In my web pages I attach the OnClick event. However this doesn't seem to
intercept right-click events. Is there another event I need to attach or is
it something else?

thx

Brynn
www.coolpier.com

I participate in the group to help give examples of code.
I do not guarantee the effects of any code posted.
Test all code before use!
 
E

Evertjan.

Brynn wrote on 24 jan 2004 in comp.lang.javascript:
I know how to do it .. but I don't agree with the practice or ability
of it.
sorry,

While not all functions are advisable for a public page,
special rightclicking can be very useful.

I have a personal page for housekeeping a database.
This page is IP specific and password protected.
Leftclicking on a record makes that record accessable for maintenance.
Rightclicking is for deleting the record after confirm().

[The easy thing for a personal page is that you write only for your own
browser, IE6 in my case]

<div class=myrecord
onclick="leftclickfunction(this)"
oncontextmenu="rightclickfunction(this)"
 
M

Martin Honnen

Robert said:
In my web pages I attach the OnClick event. However this doesn't seem to
intercept right-click events. Is there another event I need to attach or is
it something else?

You can use the onmousedown event handler and check which mouse button
has been pressed, however most people asking for right click are looking
to intercept the context menu being requested, IE5+ and Netscape 6/7
allow that with the
oncontextmenu
handler
 
J

Jason Daviau

The event you are looking for is onContextMenu.

Ex
onContextMenu="return YourMethod('Your Params')"

Make sure your method returns false or the ie menu will still appear.
 
G

Grant Wagner

That code makes me glad I have a scriptlet on my Links toolbar that does:

javascript:void(function
(){document.body.oncontextmenu=null;window.onmousedown=null;window.onmouseup=null;}());

So when I do find myself surfing the Web with IE (because of the horrible design
of some sites which make it almost impossible to view the site with anything
other then IE), I can disable the author's misguided attempts to "help me out"
by messing with the functionality of my browser.

Jason said:
The event you are looking for is onContextMenu.

Ex
onContextMenu="return YourMethod('Your Params')"

Make sure your method returns false or the ie menu will still appear.

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top