Mimicing the Copy Command with Javascript

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

    Mimicing the Copy Command with Javascript

    Hi!

    I have perhaps a strange question... I have a javascript that
    activates on a right click and shows the user a little menu of links.
    However, by doing so, it disables the users ability to use the Copy
    Command when doing a normal right click. I know that in some cases
    this would be good for someone who wants to make it harder to copy
    pictures from their site... but in this case I WANT people to be able
    to copy the pictures....

    Is there any way that I can replicate the normal Copy Command in
    Javascript so I can add that as an item on the menu? The menu already
    gets the x,y coordinates of the mouse click if that helps..

    Any ideas?

    Thanks!

    -Sarah.




  • Seeker

    #2
    Re: Mimicing the Copy Command with Javascript


    "Sarah" <no-spam~sarah@zhou se.com> wrote in message
    news:1scd405phn bqs47ja0v1d2cks b4spj5vlk@4ax.c om...[color=blue]
    > Hi!
    >
    > I have perhaps a strange question... I have a javascript that
    > activates on a right click and shows the user a little menu of links.
    > However, by doing so, it disables the users ability to use the Copy
    > Command when doing a normal right click. I know that in some cases
    > this would be good for someone who wants to make it harder to copy
    > pictures from their site... but in this case I WANT people to be able
    > to copy the pictures....
    >
    > Is there any way that I can replicate the normal Copy Command in
    > Javascript so I can add that as an item on the menu? The menu already
    > gets the x,y coordinates of the mouse click if that helps..[/color]

    It's easy... DON'T MESS WITH MY RIGHT CLICK!


    Comment

    • Sarah

      #3
      Re: Mimicing the Copy Command with Javascript

      On Thu, 04 Mar 2004 04:57:43 GMT, "Seeker" <dont.spam@me.h ere> wrote:
      [color=blue]
      >
      >"Sarah" <no-spam~sarah@zhou se.com> wrote in message
      >news:1scd405ph nbqs47ja0v1d2ck sb4spj5vlk@4ax. com...[color=green]
      >> Hi!
      >>
      >> I have perhaps a strange question... I have a javascript that
      >> activates on a right click and shows the user a little menu of links.
      >> However, by doing so, it disables the users ability to use the Copy
      >> Command when doing a normal right click. I know that in some cases
      >> this would be good for someone who wants to make it harder to copy
      >> pictures from their site... but in this case I WANT people to be able
      >> to copy the pictures....
      >>
      >> Is there any way that I can replicate the normal Copy Command in
      >> Javascript so I can add that as an item on the menu? The menu already
      >> gets the x,y coordinates of the mouse click if that helps..[/color]
      >
      >It's easy... DON'T MESS WITH MY RIGHT CLICK!
      >[/color]
      Thank you... that's very helpful...

      Comment

      • Michael Winter

        #4
        Re: Mimicing the Copy Command with Javascript

        On Thu, 04 Mar 2004 04:49:48 GMT, Sarah <no-spam~sarah@zhou se.com> wrote:

        [snip]
        [color=blue]
        > Is there any way that I can replicate the normal Copy Command in
        > Javascript so I can add that as an item on the menu? The menu already
        > gets the x,y coordinates of the mouse click if that helps..[/color]

        [snip]

        There is no standard way. That is, no way that will work on all browsers.
        If a solution is available, it is specific to a subset of browsers, and I
        don't know it. I couldn't even find a way with IE, so I doubt it's
        possible.

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Richard Formby

          #5
          Re: Mimicing the Copy Command with Javascript


          "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
          news:opr4bzqyzv 5vklcq@news-text.blueyonder .co.uk...[color=blue]
          > On Thu, 04 Mar 2004 04:49:48 GMT, Sarah <no-spam~sarah@zhou se.com> wrote:
          >
          > [snip]
          >[color=green]
          > > Is there any way that I can replicate the normal Copy Command in
          > > Javascript so I can add that as an item on the menu? The menu already
          > > gets the x,y coordinates of the mouse click if that helps..[/color]
          >
          > [snip]
          >
          > There is no standard way. That is, no way that will work on all browsers.
          > If a solution is available, it is specific to a subset of browsers, and I
          > don't know it. I couldn't even find a way with IE, so I doubt it's
          > possible.[/color]


          This has been discussed here a number of times before.

          The general consensus is that you can not replicate many of the functions
          provided in the context menu so don't mess with it. Leave it right alone.

          Provide the functionality elsewhere.

          Cheers
          Richard.


          Comment

          • Michael Winter

            #6
            Re: Mimicing the Copy Command with Javascript

            On Thu, 04 Mar 2004 12:21:56 GMT, Richard Formby <rf302@cueword. com.au>
            wrote:
            [color=blue]
            > "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in message
            > news:opr4bzqyzv 5vklcq@news-text.blueyonder .co.uk...[/color]

            [mimicking context menu functionality]
            [color=blue][color=green]
            >> There is no standard way. That is, no way that will work on all
            >> browsers. If a solution is available, it is specific to a subset
            >> of browsers, and I don't know it. I couldn't even find a way with
            >> IE, so I doubt it's possible.[/color]
            >
            > This has been discussed here a number of times before.[/color]

            I know. I think I even commented at the last occasion.
            [color=blue]
            > The general consensus is that you can not replicate many of the functions
            > provided in the context menu so don't mess with it. Leave it right alone.[/color]

            And I whole-heartedly agree. However, the OP was already given that
            opinion, though more tersely, and didn't like it. I thought that I'd make
            a more definite point.

            Mike

            --
            Michael Winter
            M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

            Comment

            • Ivo

              #7
              Re: Mimicing the Copy Command with Javascript

              People wrote:[color=blue]
              > [mimicking context menu functionality]
              >[color=green][color=darkred]
              > >> There is no standard way. That is, no way that will work on all
              > >> browsers. If a solution is available, it is specific to a subset
              > >> of browsers, and I don't know it. I couldn't even find a way with
              > >> IE, so I doubt it's possible.[/color]
              > >
              > > The general consensus is that you can not replicate many of the[/color][/color]
              functions[color=blue][color=green]
              > > provided in the context menu so don't mess with it. Leave it right[/color][/color]
              alone.

              In IE you can write to the clipboard using
              somevariable.ex ecCommand("Copy ");

              A compromise on contextmenus, allowing authors to customize it for their
              purpose as well as leave the default contextmenu inplace for everyone else,
              is to check whether the menu is currently visible when a right-click occurs,
              and if so, display the other contextmenu. A (bit old by now) approach that
              combines the contxtmenu with whatever may have been scripted, can be found
              at <URL: http://4umi.com/web/javascript/contextmenu.htm >. Rightclick once
              and you get some silly options, rightclick again and you get the default
              menu!
              HTH
              Ivo


              Comment

              • Richard Cornford

                #8
                Re: Mimicing the Copy Command with Javascript

                Ivo wrote:
                <snip>[color=blue]
                > In IE you can write to the clipboard using
                > somevariable.ex ecCommand("Copy ");[/color]

                Are you proposing that individual elements have execCommand methods in
                IE? They don't, execCommand is a method of document, controlRange and
                TextRange implying a need to make/generate a selection/Range prior to
                attempting to save it to the clipboard..

                (There is also a whole procedure for examining browser support for any
                particular execCommand operation:- queryCommandSup ported,
                queryCommandEna bled.)

                <snip>[color=blue]
                > ... . Rightclick once and you get some silly options,
                > rightclick again and you get the default menu![/color]

                Or you get nothing, or just the original context menu, depending on the
                browser. Supplementary context menus are just not achievable
                cross-browser, which is why the best advice is to leave them alone
                (except possibly on Intranet applications). After all, if it is based on
                code by Yep (which I will happily accept as normally state of the art)
                and it still isn't up to the task then it is almost certain that it just
                cannot be done.

                Richard.


                Comment

                • Yann-Erwan Perio

                  #9
                  Re: Mimicing the Copy Command with Javascript

                  Richard Cornford wrote:[color=blue]
                  > Ivo wrote:[/color]
                  [color=blue][color=green]
                  >>In IE you can write to the clipboard using
                  >> somevariable.ex ecCommand("Copy ");[/color][/color]

                  JFTR Gecko offers a clipboardhelper component, which however requires
                  security privileges to be set. Still, implementing a copy feature in
                  other browsers is probably impossible, the way a browser should interact
                  with the OS has nothing to do with client-side scripting, so they'd
                  likely not offer an interface for doing so (IE and Mozilla, being
                  scripted outside a web environment, may have a legitimate reason to
                  provide such components).
                  [color=blue][color=green]
                  >>... . Rightclick once and you get some silly options,
                  >>rightclick again and you get the default menu![/color][/color]
                  [color=blue]
                  > Or you get nothing, or just the original context menu, depending on the
                  > browser. Supplementary context menus are just not achievable
                  > cross-browser, which is why the best advice is to leave them alone
                  > (except possibly on Intranet applications).[/color]

                  IMBW, but I like to make a difference between these system-related
                  contextual menus (which should, as you say, be left alone) and
                  document-related contextual menus (which after all are like any
                  navigational menu), easily created and called (for instance by a click
                  with a key modifier).
                  [color=blue]
                  > After all, if it is based on
                  > code by Yep[/color]

                  Nope:-) The idea (alternate conceptual menus, a rather interesting
                  approach) and the code are by Ivo, I've just provided suggestions in
                  extending it for other UAs' DOMs.

                  (which I will happily accept as normally state of the art)

                  Beware not to! I'm just doing programming as a hobby, so the way I write
                  things is just as I feel them, it's not based on sound theoretical
                  knowledge or design experience.

                  Thank you very much for your positive comments, though; coming from such
                  skilled professional as yourself, they are highly appreciated and can
                  only encourage me in getting more serious in this field.


                  Cheers,
                  Yep.

                  Comment

                  • Richard Cornford

                    #10
                    Re: Mimicing the Copy Command with Javascript

                    Yann-Erwan Perio wrote:[color=blue]
                    > Richard Cornford wrote:[/color]
                    <snip>[color=blue][color=green]
                    >>(which I will happily accept as normally state of the art)[/color]
                    >
                    > Beware not to! I'm just doing programming as a hobby,
                    > so the way I write things is just as I feel them, it's
                    > not based on sound theoretical knowledge or design
                    > experience.[/color]
                    <snip>

                    Be that as it may, I make my judgement on the code that I see. When you
                    post a complete solution what I see is just that: complete, form
                    conception through design to implementation. All of the permutations of
                    the execution environment considered and planed behaviour at the end of
                    every branch, and implemented to efficiently take advantage of the
                    language and its nature. Scripts that will get the best form whatever
                    browser they are exposed to, providing functional enhancements when they
                    can and cleanly degrading to viable underlying HTML when they can't.
                    Scripts that exemplify the appropriate use of javascript without being
                    trivial. (Subject to the occasional slips and omissions that being human
                    renders us all victims of.)

                    When so few people even perceive the intellectual challenge in Internet
                    browser script design, examples of authors that rise to the challenge
                    and produce scripts that fully address the issues are rare. You post
                    scripts that are consistently at the very top end of the range of
                    standards presented here (and often exhibit an aesthetic quality that
                    makes them interesting reading in their own right). If scripts among the
                    highest standard I see don't qualify as state of the art then I don't
                    know what would.

                    Richard.


                    Comment

                    Working...