simplest way to intercept and use right mouse click?

  • Thread starter The Natural Philosopher
  • Start date
T

The Natural Philosopher

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.

Also to make it context sensitive (of course)

If I use onmousedown and onnmouseup within specific areas of the screen,
that does the context sensitivity bit, but:-

- how to detect the right button
- how to prevent it also activating the normal function within the browser?
 
A

ace

The 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.

Also to make it context sensitive (of course)

If I use onmousedown and onnmouseup within specific areas of the screen,
that does the context sensitivity bit, but:-

- how to detect the right button
- how to prevent it also activating the normal function within the browser?

http://abeautifulsite.net/notebook_files/68/demo/
 
D

Doug Miller

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.
 
T

The Natural Philosopher

Doug said:
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?
 
D

David Mark

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.

To think I'd live to see the day. :)

Granted, these "solutions" never work 100% and there is really no
problem to solve (unless you make the mistake of trying to clobber the
context button or action.)
 
D

David Mark

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.

You would.
Also to make it context sensitive (of course)

It already is.
If I use onmousedown and onnmouseup within specific areas of the screen,
  that does the context sensitivity bit, but:-

- how to detect the right button

The right button is not always the context button. Granted browsers
smooth out those wrinkles (more or less.)
- how to prevent it also activating the normal function within the browser?

Can't do it 100% reliably for all browsers and you shouldn't try.
Leave the context clicks alone. Thanks!
 
T

The Natural Philosopher

David said:
You would.


It already is.


The right button is not always the context button. Granted browsers
smooth out those wrinkles (more or less.)


Can't do it 100% reliably for all browsers and you shouldn't try.
Leave the context clicks alone. Thanks!

Q. How to build a plane to fly across the channel?
A. Dont. Swimming is safer.

Gee, what a great help you really are.

*plonk*
 
D

David Mark

Q. How to build a plane to fly across the channel?
A. Dont. Swimming is safer.

Q. How to shoot myself in the foot?
A. Don't. Shoot something else.
Gee,  what a great help you really are.

*plonk*

You should ask for a refund on that lobotomy. They botched it.
 
D

David Mark

Doug said:
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.
 
T

The Natural Philosopher

David said:
Doug said:
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.

Excuse me while I laugh...
 
D

David Mark

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 allrespects
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 inother
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.

You "plonked" me. Remember? Two messages back in this very thread.
Excuse me while I laugh...

It's the best medicine. :)
 
A

ace

Doug said:
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]

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?
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.

So you're suggesting something or just being shocked?
 
A

ace

The said:
It seems to work pretty well and covers most bases.

Anyone care to comment on it?

Didn't try your code out, but you can make your own jQuery plugin with
it if it's better at handling right clicks.
 
D

David Mark

Doug said:
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]

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?
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.

So you're suggesting something or just being shocked?

He is being facetious. As in, the Cubs lost again; what a shock!
 
D

David Mark

Didn't try your code out, but you can make your own jQuery plugin with
it if it's better at handling right clicks.

Are you suggesting something or just being silly.
 
D

Doug Miller

Doug said:
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]

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.

Not sure why it works in your installation and not in mine...
 
D

David Mark

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]
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 prettysure
there is *not* a problem with Firefox, just a problem with jQuery.

Not sure why it works in your installation and not in mine...

That's the jQuery anthem.

[snip]
 
T

The Natural Philosopher

ace said:
Didn't try your code out, but you can make your own jQuery plugin with
it if it's better at handling right clicks.

Why would I ever want to use Jquery?
 
L

Laurent vilday

Doug Miller :
ace said:
Doug Miller :
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]
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.

Not sure why it works in your installation and not in mine...

FF 3.0.10

about:config in the URL "area"

dom.event.contextmenu.enabled = false
 
D

Doug Miller

Doug Miller :
ace said:
Doug Miller :

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]
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.

Not sure why it works in your installation and not in mine...

FF 3.0.10

about:config in the URL "area"

dom.event.contextmenu.enabled = false
Toggling that to 'true' causes the page to behave as advertised -- which of
course means that the script on that page is pretty well useless, since
whether it works or not depends on a browser configuration setting that is
completely outside the script's control.
 

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
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top