473,842 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event Handling Question

I was trying to display a custom context menu in javascript. I wanted to
capture a right mouse click.

I added an eventListener to a "div" like this..

element,addEven tListener ("click", myfunc, true);

When I tried to debug it, it seems to react fine to a left mouse click,
but it totally ignores the right mouse click.

Can somebody please explain why?

(When I changed the "click" to "mousedown" , it seems to work fine for
both right mouse button as well as the left.)

Thank you.
Aug 6 '07 #1
8 1621
On Aug 6, 4:37 am, Louis <t051...@hotmai l.comwrote:
I was trying to display a custom context menu in javascript. I wanted to
capture a right mouse click.

I added an eventListener to a "div" like this..

element,addEven tListener ("click", myfunc, true);

When I tried to debug it, it seems to react fine to a left mouse click,
but it totally ignores the right mouse click.

Can somebody please explain why?

(When I changed the "click" to "mousedown" , it seems to work fine for
both right mouse button as well as the left.)
You sort-of answered your own question. Certainly onmousedown is not
appropriate to display a context menu (onmouseup is correct.) You
also need oncontextmenu for some browsers.

And BTW, Opera won't work like this at all, so you need an alternative
(eg ctrl-left, middle, etc.)

Aug 6 '07 #2
Louis wrote:
I was trying to display a custom context menu in javascript. I wanted to
capture a right mouse click.

I added an eventListener to a "div" like this..

element,addEven tListener ("click", myfunc, true);
The first comma is probably only a typo. And are you sure you want/need
event capturing (the third argument being `true')?
When I tried to debug it, it seems to react fine to a left mouse click,
but it totally ignores the right mouse click.

Can somebody please explain why?
It is not supposed to. The `click' event fires, in my words, when the
activation key (usually Return/Enter) is pressed and the element has the
focus, or when the primary pointing device button (with a mouse, the left
button unless configured for left-handed people, provided there is a right
button at all) is pushed down and released (i.e. it is clicked) when the
pointer is positioned over the element.

W3C DOM Level 2 Events specifies the event as follows:

,-<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-eventgroupings-mouseevents>
|
| click
| The click event occurs when the pointing device button is clicked over
| an element. A click is defined as a mousedown and mouseup over the same
| screen location. The sequence of these events is:
|
| mousedown
| mouseup
| click

Note that the specification says "the pointing device button", which means
there is no provision for more than one button.
(When I changed the "click" to "mousedown" , it seems to work fine for
both right mouse button as well as the left.)
Works as designed. However, different to the `click' event, `the
`mousedown' event fires already when the key or button is pushed.

You really should leave the function of the secondary button as it is.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 6 '07 #3
On Aug 6, 4:27 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
You really should leave the function of the secondary button as it is.
I disagree on this point. I do acknowledge that it's bad design to,
say, disable the secondary button across your entire site, as that
would change the behavior of the page from the user's expected
behavior, but from within a designated and controlled area, using the
events as specified by the W3C should be completely allowed. That is
to say, the function of the secondary (and tertiary!) button may
change with respect to the page's intended use of the mouse as the
main interaction device.

For example, say I'm making a Minesweeper clone in DHTML. The right-
click button is by far the most intuitive interface for performing
'safety' actions on the grid, and right-click+left-click is the
accepted, familiar way to "clear" a surrounding group of squares on
the grid. However, in the W3C model, there is no native way of
detecting multiple mouse buttons used in a mouse event, and without
reliable preventDefault behavior, I'm likely to trigger any one of
several gestures in Opera or Firefox. (And that's after I force my
Opera-driven users to upgrade to 8.5+ and turn on "Allow script to
receive right-clicks" in a menu buried in Preferences.)

Or say I'm creating an interactive tab bar for a client's intranet
application, and they'd like to leave browser choice for their users
open for choice. Shouldn't I be able to duplicate the tab behavior of
any other tabbed browser, where middle-click closes the tab? Well,
there's no way (I've found) for preventing the default 'turn on the
scroll anchor' on mousedown. (Assuming I could get Firefox to
recognize the middle-click in the first place.)
These seem like simple implementations of a pretty clearly-defined
standard, that browser manufacturers have decided to straight-up deny
in what I assume to be the name of "protecting their users from
malicious [read: annoying] web authors". The days of preventing a
dozen popup windows from Geocities are long since over; these simple
features should be given back to Web authors. If they choose to abuse
them, there's no real harm that can be done to the page or the user's
client due to other Javascript security measures, and if they affect
the user's experience adversely enough, the users will leave and those
practices will die with the author's business.

All I'm saying is, I'd really wish browsers would respond to the event
handlers I'm setting on them, and when I say preventDefault, I mean
prevent the damn default.

Aug 21 '07 #4
ko****@gmail.co m wrote:
On Aug 6, 4:27 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
>You really should leave the function of the secondary button as it is.

I disagree on this point. I do acknowledge that it's bad design to,
say, disable the secondary button across your entire site, as that
would change the behavior of the page from the user's expected
behavior, but from within a designated and controlled area, using the
events as specified by the W3C should be completely allowed.
But the Web is no such area. For example, have you ever used mouse
gestures? They are usually triggered by dragging with the secondary button.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Aug 21 '07 #5
On Aug 21, 11:51 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
But the Web is no such area. For example, have you ever used mouse
gestures? They are usually triggered by dragging with the secondary button.
I use mouse gestures every day. If you had taken the time to read the
rest of my post, you'd notice this:
without reliable preventDefault behavior, I'm likely to trigger any one of several gestures in Opera or Firefox.
Gesture functionality at the browser level is the default behavior. If
my script says "prevent that behavior when the event happens within
this part of my page", then the browser should respect that command as
issued by the script. After all, isn't that what preventDefault( ) is
for?

Aug 30 '07 #6
korisu wrote:
On Aug 21, 11:51 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
>But the Web is no such area. For example, have you ever used mouse
gestures? They are usually triggered by dragging with the secondary button.

I use mouse gestures every day. If you had taken the time to read the
rest of my post, you'd notice this:
>without reliable preventDefault behavior, I'm likely to trigger any one
of several gestures in Opera or Firefox.
I read that, and it is still irrelevant.
Gesture functionality at the browser level is the default behavior. If
my script says "prevent that behavior when the event happens within
this part of my page", then the browser should respect that command as
issued by the script. After all, isn't that what preventDefault( ) is
for?
No. And do you realize that this method is not universally supported?
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8************ *******@news.de mon.co.uk>
Aug 30 '07 #7
On Aug 30, 2:40 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
No. And do you realize that this method is not universally supported?
You're wrong; that is what preventDefault is supposed to do. I realize
that IE doesn't use preventDefault, but then again, this problem
doesn't exist in IE - it does what I tell it to, and provides me with
useful feedback. My issue concerns the browsers that claim to have
full support for the W3C Events specifications.
>From the W3C DOM Level 2 Events specification:
preventDefault
If an event is cancelable, the preventDefault method is used to
signify that the event is to be canceled, meaning any default action
normally taken by the implementation as a result of the event will not
occur. If, during any stage of event flow, the preventDefault method
is called the event is canceled. Any default action associated with
the event will not occur. Calling this method for a non-cancelable
event has no effect. Once preventDefault has been called it will
remain in effect throughout the remainder of the event's propagation.
This method may be used during any stage of event flow.

Sep 1 '07 #8
korisu wrote:
On Aug 30, 2:40 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
>No. And do you realize that this method is not universally supported?
You're wrong;
I'm not. preventDefault( ) is not intended as a method to cripple user agents.
that is what preventDefault is supposed to do.
It is still not universally supported.
I realize that IE doesn't use preventDefault, but then again, this
problem doesn't exist in IE [...]
Apparently you know only IE and not IE.
PointedEars
--
"Use any version of Microsoft Frontpage to create your site. (This won't
prevent people from viewing your source, but no one will want to steal it.)"
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Sep 1 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
12589
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
18
2898
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
2
3377
by: Marinos Christoforou | last post by:
Sorry if this has been asked before but as an inexperienced wanna-be C# programmer I wondering how to code classes to help build a standard Windows UI. For example to build a common toolbar. I would call a method from the class in the load event of my varioius windows forms, to create the toolbar, add buttons to it and set various properties as required. This is fine but I am at a loss as to how to expose the toolbar's various events...
7
1795
by: Brian Keating | last post by:
hi there this may seem like a silly question but what exactly is the difference ... ok .. that question is probably a bit ambiguous.. i know what delegates are i know what events are, i use them everyday but.. what are events needed? don't delegates do everything? look at this code normally i would use an event but i've just stuck with delegate in this instance and it still works! i'm baffelled! namespace DelegateTst
4
1757
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual protected method of the base class". Can someone please explain this with a sample code? Thanks a lot.
2
1948
by: Wavemaker | last post by:
The canonical way of declaring delegates for events is to include a parameter representing the sender as well as an EventArgs derived class (or EventArgs itself) as the second parameter representing the data that accompanies the event. For example: public delegate void MessageReceivedHandler(object sender, MessageReceivedArgs e); // ...
9
2341
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control into the place holder. This is done dynamically based on the choice they selected. This user control has a datagrid in it that supports paging. When I click on the next or prev buttons of the datagrid in a user control it should display the next page...
4
2098
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous' Effects to set Opacity to 1 for the active div and 0.5 for the inactive ones). Using prototype's event handling, I can see two ways to get this done:
3
2003
by: a | last post by:
Hi, I have a 3-column listview. It has to return the value of the cell when the user click the listview. The SelectedIndexChanged event and ItemSelectionChanged Event only return the row information (ListViewItem). If I want to return the cell value of the second and the third column, which event should I use? Let say, if the user select row 2, column 3, which event handling
1
1688
by: stmfc | last post by:
hi, for an event handling mechanism, we need an event object. (the object where the event actually occur) and we need an event handler, and we need a registration of the event handler to the event object(generator) in java, we can create a generator class by extending EventObject class. we can create an event handler class by implementing EventListener interface. for registration we can provide some registration method (e.g...
0
9865
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9709
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10303
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9446
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7853
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5694
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.