simplest way to intercept and use right mouse click?

  • Thread starter The Natural Philosopher
  • Start date
A

ace

Doug said:
[same results in Firefox 3.0.10 and Opera 9.64]
FF 3.0.10 here and when clicking right button
- there is no context menu within gray box
- there is context menu outside gray box

Are you sure that there is a problem with FF?

No, I'm not "sure that there is a problem with FF" -- in fact, I'm pretty sure
there is *not* a problem with Firefox, just a problem with jQuery.

So if this is jQuery problem as you're suggesting, the proper behavior
for right clicks can be achieved using only plain javascript?
Not sure why it works in your installation and not in mine...

As Laurent pointed out it seems that dom.event.contextmenu is the
answer, so your FF was altered or Mozilla messed up somewhere..?
 
A

ace

David said:
That's the jQuery anthem.

Why did the chicken cross the street?

ECMAScript orthodox church:
because it spoted the jQuery on the other side and wanted to smack it.
 
D

David Mark

Why did the chicken cross the street?

The road?
ECMAScript orthodox church:
Huh?

because it spoted the jQuery on the other side and wanted to smack it.

Chickens don't like jQuery either? I hadn't given that species enough
credit.
 
D

Doug Miller

Doug said:
[same results in Firefox 3.0.10 and Opera 9.64]
FF 3.0.10 here and when clicking right button
- there is no context menu within gray box
- there is context menu outside gray box

Are you sure that there is a problem with FF?

No, I'm not "sure that there is a problem with FF" -- in fact, I'm pretty sure
there is *not* a problem with Firefox, just a problem with jQuery.

So if this is jQuery problem as you're suggesting, the proper behavior
for right clicks can be achieved using only plain javascript?

Total non sequitur. What did I say that comes even remotely close to
suggesting that?
As Laurent pointed out it seems that dom.event.contextmenu is the
answer, so your FF was altered or Mozilla messed up somewhere..?

I think mine was set to the default value... Anyway, the lesson here is that
the script's behavior is dependent on browser settings that the script cannot
control, and its utility is therefore rather limited.
 
T

The Natural Philosopher

ace said:
Don't know about your preferences; I was making a comment on your script.
I posted up someone else's script.

Which then was taken over by people talking about a jquery script.

I'm still not clear as to what didn't work for whom.
 
T

The Natural Philosopher

Doug said:
I think mine was set to the default value... Anyway, the lesson here is that
the script's behavior is dependent on browser settings that the script cannot
control, and its utility is therefore rather limited.

Now correct me if I am wrong, but this is the javascript group, right?

Ergo, any code that we write that is intended to be executed by a
javascript interpreter in a browser is, in fact totally subject to the
browser having the magic box 'allow javascript' ticked, right?

So, with respect, what the **** has whether something can be switched
off in a browser got to do with anything . It ALL can be switched off in
a browser.
 
T

The Natural Philosopher

The said:
Now correct me if I am wrong, but this is the javascript group, right?

Ergo, any code that we write that is intended to be executed by a
javascript interpreter in a browser is, in fact totally subject to the
browser having the magic box 'allow javascript' ticked, right?

So, with respect, what the **** has whether something can be switched
off in a browser got to do with anything . It ALL can be switched off in
a browser.
Oh and while I am in teh mood. lest review this thread in a broader context.

I ask a question - a reasonable question. I get basically responses

'use jquery'
'its a stupid thing to want to do'.

NO ONE has actually posted ANY code whatsoever that has any chance of
working at all, except me, - and I found it on the net.

Now I have to ask myself, what is this NG all about?

Is it a pissing contest in which people who have no solutions to offer,
attempt to outdo each other in willy waving, and tearing any attempt to
solve a real life problem apart with reasons given being that - like
javascript itself 'it wont work if the user switches it off'.

It wont fucking work if they never visit the site either, comrades.

And as I have said before, the thing I am working on is an application
where the browser can be set to whatever it has to be set to, to work.

I cant get over the distinct impression here, that very few people here
actually ever write any javascript at all.
 
D

Doug Miller

Now correct me if I am wrong, but this is the javascript group, right?

Ergo, any code that we write that is intended to be executed by a
javascript interpreter in a browser is, in fact totally subject to the
browser having the magic box 'allow javascript' ticked, right?

So, with respect, what the **** has whether something can be switched
off in a browser got to do with anything . It ALL can be switched off in
a browser.

The point which you appear to have missed is that a script that only works
part of the time isn't of much more use than a script that never works (or is
never executed).
 
L

Lasse Reichstein Nielsen

The Natural Philosopher said:
Title says it all.

I would like to intercept the right mouse click and have it do
something other than what it does by default within a browser context.

The simplest way is to use the oncontextmenu event handler.
Only problem is that it doesn't work in older browsers, or in Opera.
It does work in (quick test): Safari 4, Firefox 3, IE 7 and Chrome 2.

If that's a problem, you have to use the old-style
onclick/onmouseup/onmousedown handler and try to discover which button
was clicked, or with which modifier.
Also to make it context sensitive (of course)

Different handlers.

/L
 
G

Garrett Smith

The said:
David said:
Doug Miller wrote:
http://abeautifulsite.net/notebook_files/68/demo/
Does not work as advertised: the behavior of the right mouse button
inside the
box labelled "No context menu in this container" is identical in
all respects
with its behavior *outside* that box.
[same results in Firefox 3.0.10 and Opera 9.64]
Does work as advertised in IE 7.0.6001, though...
Imagine my surprise -- a JQuery app that works in IE and is broken
in other
browsers. What a shock.
Yep. And I don't call jquery 'simple'

I found this on the net:-

<a href="javascript:void(null)"
onmousedown="return buttonalert(event)" onmouseup="return
dont(event)"
onclick="return dont(event)" ondblclick="return dont(event)"
oncontextmenu="return dont(event)"
Click here with various mouse buttons to test</a>
</center>
<script language="Javascript">
function buttonalert(event)
{
var button;
if (event.which == null)
button= (event.button < 2) ? "LEFT" :
((event.button == 4) ? "MIDDLE" : "RIGHT");
else
button= (event.which < 2) ? "LEFT" :
((event.which == 2) ? "MIDDLE" : "RIGHT");
alert(button);
dont(event);}

function dont(event)
{
if (event.preventDefault)
event.preventDefault();
else
event.returnValue= false;
return false;}

</script>

It seems to work pretty well and covers most bases.

Anyone care to comment on it?

Yes, like most snippets you find on the Web, it's pure horseshit.
Look again.
So, its pure horseshit, you can find time to say so, but not why.

The problems are partiallay explained in two parts of the FAQ:
http://jibbering.com/faq/#javascriptURI

http://jibbering.com/faq/#disableRightClick

The well-documented problems that exist with javascript pseudo protocol
not stop people from using it. Look at Google Maps, for example.

The archives includes discussion about "disabling the right mouse
button" and why the question itself is flawed. I don't have a mouse, and
if I did, your code cannot affect it. It can, in some browsers, affect
the context menu.

It has been discussed quite thoroughly here. Please search the archives.

And that script really is junk. Does not pass review.

Garrett
 
T

The Natural Philosopher

Conrad said:
If this is for an intranet app, then what's the big problem? You've got
the code that works with one specific setup, and you can enforce that
setup. Problem solved, you can move on to the next task. You can't
expect people to know that "the thing you're working on" isn't intended
for a normal website.

Why do they always assume it is?

And the same applies: There is so much configurability in a browser,
that frankly, javascript becomes totally irrelevant if you want to code
to 'lowest common factor' standards..

And what is a 'normal website' anyway?
 
T

The Natural Philosopher

Garrett said:
The said:
David said:
On May 22, 10:41 am, The Natural Philosopher <[email protected]>
wrote:
Doug Miller wrote:
http://abeautifulsite.net/notebook_files/68/demo/
Does not work as advertised: the behavior of the right mouse
button inside the
box labelled "No context menu in this container" is identical in
all respects
with its behavior *outside* that box.
[same results in Firefox 3.0.10 and Opera 9.64]
Does work as advertised in IE 7.0.6001, though...
Imagine my surprise -- a JQuery app that works in IE and is broken
in other
browsers. What a shock.
Yep. And I don't call jquery 'simple'

I found this on the net:-

<a href="javascript:void(null)"
onmousedown="return buttonalert(event)" onmouseup="return
dont(event)"
onclick="return dont(event)" ondblclick="return dont(event)"
oncontextmenu="return dont(event)"
Click here with various mouse buttons to test</a>
</center>
<script language="Javascript">
function buttonalert(event)
{
var button;
if (event.which == null)
button= (event.button < 2) ? "LEFT" :
((event.button == 4) ? "MIDDLE" : "RIGHT");
else
button= (event.which < 2) ? "LEFT" :
((event.which == 2) ? "MIDDLE" : "RIGHT");
alert(button);
dont(event);}

function dont(event)
{
if (event.preventDefault)
event.preventDefault();
else
event.returnValue= false;
return false;}

</script>

It seems to work pretty well and covers most bases.

Anyone care to comment on it?

Yes, like most snippets you find on the Web, it's pure horseshit.
Look again.
So, its pure horseshit, you can find time to say so, but not why.

The problems are partiallay explained in two parts of the FAQ:
http://jibbering.com/faq/#javascriptURI

I cant see anything there remotrely to do with right mouse clicks.


And that merely tells me older browsers may not work so well. Well
really, who would have thought it?

The well-documented problems that exist with javascript pseudo protocol
not stop people from using it. Look at Google Maps, for example.

The archives includes discussion about "disabling the right mouse
button" and why the question itself is flawed. I don't have a mouse, and
if I did, your code cannot affect it. It can, in some browsers, affect
the context menu.

Good, then you wont be accessing this particular code.
 
R

RobG

Why do they always assume it is?

Perhaps the FAQ has the answer:

| 1.2 What questions are on-topic for comp.lang.javascript?
|
| The comp.lang.javascript newsgroup deals with ECMAScript
| languages, so any questions about JavaScript or JScript
| are welcome. However, the majority of questions sent to
| this group relates to javascript in a web browser. If you
| are experiencing issues with a particular browser, or the
| host is not a browser at all, please make this information
| clear.

Which infers that if you aren't asking about web browsers in general
as used on the WWW (which covers the majority of questions here), then
it helps if you say so.

And the same applies: There is so much configurability in a browser,
that frankly, javascript becomes totally irrelevant  if you want to code
to 'lowest common factor' standards..

Not at all. There are well known techniques for making web sites
widely accessible, they don't preclude the use of javascript.

And what is a 'normal website' anyway?

One on the WWW perhaps.
 
T

The Natural Philosopher

RobG said:
Perhaps the FAQ has the answer:

| 1.2 What questions are on-topic for comp.lang.javascript?
|
| The comp.lang.javascript newsgroup deals with ECMAScript
| languages, so any questions about JavaScript or JScript
| are welcome. However, the majority of questions sent to
| this group relates to javascript in a web browser. If you
| are experiencing issues with a particular browser, or the
| host is not a browser at all, please make this information
| clear.

Which infers that if you aren't asking about web browsers in general
as used on the WWW (which covers the majority of questions here), then
it helps if you say so.

Of course I was talking about web BRIOSWERS as used on..etc.

The question was what SITES. Not what BROWSERS.
Not at all. There are well known techniques for making web sites
widely accessible, they don't preclude the use of javascript.



One on the WWW perhaps.
That is again a moot point. What is 'on the www'?

My test site here is 'on the www' and accessible by anyone who knows the
right magic spells.

Fortunately almost no one does.

The real issue is the target audience you are designing for, and whether
or not you actually care whether a deaf dumb and blind idiot running a
braille keyboard and lynx on OS/2 over a 300 baud modem to a braille
output device is truly someone you want or need to make your site
accessible to..

In reality 99.99% of your target market COULD run firefox, as there is
probably only a handful of platforms it hasn't been ported to, and the
vast majority will be running IE6,7 or 8..with a smattering of safari
mac users..and a few people on other odd browsers for use on mobile
phones and the like.
 
D

David Mark

Of course I was talking about web BRIOSWERS as used on..etc.

The question was what SITES. Not what BROWSERS.

Stop shouting. Are you psychotic?
That is again a moot point. What is 'on the www'?

You are a moot point.
My test site here is 'on the www' and accessible by anyone who knows the
right magic spells.

What does that mean?
Fortunately almost no one does.

Oh, nothing. Screw your 20 questions test site. I still think your
"Intranet project" is all in your head.
The real issue is the target audience you are designing for, and whether
or not you actually care whether a deaf dumb and blind idiot running a
braille keyboard and lynx on OS/2 over a 300 baud modem to a braille
output device is truly someone you want or need to make your site
accessible to..

On behalf of the blind, deaf and dumb, go **** yourself.
In reality 99.99% of your target market COULD run firefox, as there is
probably only a handful of platforms it hasn't been ported to, and the
vast majority will be running IE6,7 or 8..with a smattering of safari
mac users..and a few people on other odd browsers for use on mobile
phones and the like.

You are babbling.
 
A

ace

Conrad said:
"Altered" is not the right word. It's not a hidden preference - it's
right there on the Preferences -> Content tab. Since such an option
exists, the script has to deal with the fact that the context menu event
and "right" mouse button events can't be trusted, and you'll have to
find another way to show your own context menu.

Or, you can work with browser defaults and cover majority of users.
Searching for lowest common denominator among features could lead to
lynx from '96 and I'm not sure how much of dom and js it understands.

BTW... "ECMAScript orthodox church"? Nice one :)

You know, there has to be something opposite to the cults and pagans. :)
 
A

ace

Doug said:
[same results in Firefox 3.0.10 and Opera 9.64]
FF 3.0.10 here and when clicking right button
- there is no context menu within gray box
- there is context menu outside gray box

Are you sure that there is a problem with FF?
No, I'm not "sure that there is a problem with FF" -- in fact, I'm pretty sure

So if this is jQuery problem as you're suggesting, the proper behavior
for right clicks can be achieved using only plain javascript?

Total non sequitur. What did I say that comes even remotely close to
suggesting that?

You wrote that there is problem with jQuery, so I wondered if problem
could be avoided by dropping it and using only native js.
I think mine was set to the default value... Anyway, the lesson here is that
the script's behavior is dependent on browser settings that the script cannot
control, and its utility is therefore rather limited.

yep, but we could also blame it on the jquery which is pretty popular
here on the newsgroup. :)
 
D

David Mark

Doug said:
[same results in Firefox 3.0.10 and Opera 9.64]
FF 3.0.10 here and when clicking right button
- there is no context menu within gray box
- there is context menu outside gray box
Are you sure that there is a problem with FF?
No, I'm not "sure that there is a problem with FF" -- in fact, I'm pretty
sure
there is *not* a problem with Firefox, just a problem with jQuery.
So if this is jQuery problem as you're suggesting, the proper behavior
for right clicks can be achieved using only plain javascript?
Total non sequitur. What did I say that comes even remotely close to
suggesting that?

You wrote that there is problem with jQuery, so I wondered if problem
could be avoided by dropping it and using only native js.
I think mine was set to the default value... Anyway, the lesson here isthat
the script's behavior is dependent on browser settings that the script cannot
control, and its utility is therefore rather limited.

yep, but we could also blame it on the jquery which is pretty popular
here on the newsgroup. :)

The jQuery code has been *dissected* here on the newsgroup. Read the
reports and you'll be able to spot when jQuery is fouling something
up. It's easy when you know what it is doing (as opposed to relying
on anecdotes and documentation from those who don't.)
 

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,100
Messages
2,570,635
Members
47,241
Latest member
HumbertoSt

Latest Threads

Top