Right Click Menu

S

Simon Wigzell

How can I customize the menu that appears when you right click on a
particular element of a web page? In a cross platform compatible way,
thanks.
 
R

Randy Webb

Simon said:
How can I customize the menu that appears when you right click on a
particular element of a web page? In a cross platform compatible way,
thanks.

You can't.
 
D

David Dorward

Simon said:
How can I customize the menu that appears when you right click on a
particular element of a web page? In a cross platform compatible way,
thanks.

Customise? You can't. Entirely replace? You can in some browsers. Its so
annoying (even when it isn't being abused in an effort to remove the menu
entirely) that most modern browsers now have an option to disable that bit
of JavaScript without affecting the rest of it. It really isn't likely to
be worth the effort.
 
S

Sandfordc

Well,

If your still interested all you have to do is:

1) Set an event capture eg. onmousedown=
2) Capture the cordinates of the mouse at that time (sorry i forgot the
command)
3) Set a DIV or SPAN to appear there with the contents of your menu

Best Regards,
Sandfordc
www.JavaScript-Central.tk
 
R

Richard Cornford

Sandfordc said:
Well,

If your still interested all you have to do is:

Why have you posted this as a response to David Dorward? David a) knows
how to do this, and b) doesn't want to do it. It would make more sense
to respond to the OP, who wants to do it but doesn't know how.
1) Set an event capture eg. onmousedown=

A context menu facility makes more sense attached to - oncontextmenu -,
else alternative methods of triggering the menu are unavailable (such as
the contetxmenu button that appears on keyboards). Capturing mousedown
is not a lot of use unless you can distinguish between non-content menu
mousedown activity and activity that will open a context menu on the
system. The usual approach of testing for the right button being pressed
misses a lot of possible user configuration permutations.
2) Capture the cordinates of the mouse at that time
(sorry i forgot the command)

There is no mouse co-ordinates 'command'. Mouse co-ordinated, relative
to numerous co-ordinate systems (page, viewport, screen and so on), are
available as properties of (mouse event) objects, and must be extracted
(and usually normalised to a consistent system for use).
3) Set a DIV or SPAN to appear there with the contents
of your menu

DIV and SPAN elements have a lot of similarities, being semantically
neutral elements that exist for the application of CSS to arbitrary
sections of mark-up. They also have a very significant difference in
that DIV is a block element and SPAN is an inline element. That
difference means that in any context of use (including this one) only
one of them could be appropriate, to the exclusion of the other.
Suggesting that they may be interchangeable, or that the choice between
the two is arbitrary, implies a superficial grasp of HTML.

In addition; triggering a scripted context menu from any event (mouse
own or contextmenu) will make for a confusing GUI unless the browser's
context menu is in some way blocked/cancelled. As some environments
allow the user to veto the blocking/cancelling of the browser's context
menu this entire notion is inappropriate in a public Internet context.

Richard.
 
S

Sandfordc

Alright if you say so and there is a comand to retrieve the co-ordiates
of the mouse.
 
S

Sandfordc

Alright if you say so and there is a comand to retrieve the co-ordiates
of the mouse.
 
R

Richard Cornford

Sandfordc said:
Alright if you say so and there is a comand to retrieve
the co-ordiates of the mouse.

I don't think that statement would have been coherent even if it had a
context.

Richard.
 
S

Sandfordc

Well let me tell you I sure damn well found those darn things.

event.clientX
event.clientY

or for a nifty one tells you where you are on the page relative to the
top left of the page.

x=event.clientX + document.body.scrollTop
y=event.clientY + document.body.scrollLeft

But I guess theres something wrong with that to right?
 
R

Richard Cornford

Sandfordc wrote:

Again a response with no context. You should familiarise yourself with
the correct post formatting; See the group's FAQ:-

Well let me tell you I sure damn well found those
darn things.

event.clientX
event.clientY

or for a nifty one tells you where you are on the page
relative to the top left of the page.

x=event.clientX + document.body.scrollTop
y=event.clientY + document.body.scrollLeft

But I guess theres something wrong with that to right?

Do these represent what you have been referring to as 'commands'? The
first are property accessors, the second expressions where property
accessors act as operands for an operator. Property accessors are
passive references to values, while to term 'command' implies some
active behaviour. However, that term is not used in the context of
javascript, even to refer to the language's built in global functions.

And yes, the process is poor. The ability to refer to an event by the
unqualified identifier - event - is a long way from being universal.
The - clientX/Y - properties of event objects (where implemented) do not
consistently refer to the same relative values. The - scrollTop/Left -
properties are not the preferred means of reading the degree to which a
page is scrolled, and where the better alternatives are not available it
is necessary to consider the rendering mode of the browser before
choosing the object from which the scrollTop/Left properties should be
read. And even in IE, operating in quirks mode, where your suggested
expressions should be at least error free, it is necessary to adjust the
mouse co-ordinates by the dimensions of the root-element border in order
to produce results that relate to page co-ordinates.

Richard.
 
M

Mick White

Sandfordc said:
Well let me tell you I sure damn well found those darn things.

event.clientX
event.clientY

or for a nifty one tells you where you are on the page relative to the
top left of the page.

x=event.clientX + document.body.scrollTop
y=event.clientY + document.body.scrollLeft

But I guess theres something wrong with that to right?


Good guess.
Mick
 
R

RobG

Sandfordc said:
Well let me tell you I sure damn well found those darn things.

event.clientX
event.clientY

or for a nifty one tells you where you are on the page relative to the
top left of the page.

x=event.clientX + document.body.scrollTop
y=event.clientY + document.body.scrollLeft

But I guess theres something wrong with that to right?

Since you seem to be keen to play with this stuff, you could do worse
than to have a read of Peter-Paul Koch's pages at Quirksmode:

<URL:http://www.quirksmode.org/viewport/intro.html>

Especially look at the 'experiments' link on the above page:

<URL:http://www.quirksmode.org/viewport/experiments.html>

There's a bundle of other interesting things there too if you go to the
home page.
 

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,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top