Right Click Menu

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wigzell

    Right Click Menu

    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.


  • Randy Webb

    #2
    Re: Right Click Menu

    Simon Wigzell wrote:
    [color=blue]
    > 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.[/color]

    You can't.

    --
    Randy
    comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

    Comment

    • David Dorward

      #3
      Re: Right Click Menu

      Simon Wigzell wrote:
      [color=blue]
      > 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.[/color]

      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.

      --
      David Dorward <http://blog.dorward.me .uk/> <http://dorward.me.uk/>
      Home is where the ~/.bashrc is

      Comment

      • Sandfordc

        #4
        Re: Right Click Menu

        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


        Comment

        • Richard Cornford

          #5
          Re: Right Click Menu

          Sandfordc wrote:[color=blue]
          > Well,
          >
          > If your still interested all you have to do is:[/color]

          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.
          [color=blue]
          > 1) Set an event capture eg. onmousedown=[/color]

          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.
          [color=blue]
          > 2) Capture the cordinates of the mouse at that time
          > (sorry i forgot the command)[/color]

          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).
          [color=blue]
          > 3) Set a DIV or SPAN to appear there with the contents
          > of your menu[/color]

          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.


          Comment

          • Sandfordc

            #6
            Re: Right Click Menu

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

            Comment

            • Sandfordc

              #7
              Re: Right Click Menu

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

              Comment

              • Richard Cornford

                #8
                Re: Right Click Menu

                Sandfordc wrote:[color=blue]
                > Alright if you say so and there is a comand to retrieve
                > the co-ordiates of the mouse.[/color]

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

                Richard.


                Comment

                • Sandfordc

                  #9
                  Re: Right Click Menu

                  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.s crollTop
                  y=event.clientY + document.body.s crollLeft

                  But I guess theres something wrong with that to right?

                  Comment

                  • Richard Cornford

                    #10
                    Re: Right Click Menu

                    Sandfordc wrote:

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

                    <URL: http://www.jibbering.com/faq/ >
                    [color=blue]
                    > 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.s crollTop
                    > y=event.clientY + document.body.s crollLeft
                    >
                    > But I guess theres something wrong with that to right?[/color]

                    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.


                    Comment

                    • Mick White

                      #11
                      Re: Right Click Menu

                      Sandfordc wrote:[color=blue]
                      > 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.s crollTop
                      > y=event.clientY + document.body.s crollLeft
                      >
                      > But I guess theres something wrong with that to right?[/color]


                      Good guess.
                      Mick

                      Comment

                      • RobG

                        #12
                        Re: Right Click Menu

                        Sandfordc wrote:[color=blue]
                        > 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.s crollTop
                        > y=event.clientY + document.body.s crollLeft
                        >
                        > But I guess theres something wrong with that to right?
                        >[/color]

                        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.htm l>

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


                        --
                        Rob

                        Comment

                        Working...