470,643 Members | 1,371 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

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.


Jul 20 '05 #1
9 2892

"Sarah" <no***********@zhouse.com> wrote in message
news:1s********************************@4ax.com...
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..


It's easy... DON'T MESS WITH MY RIGHT CLICK!
Jul 20 '05 #2
On Thu, 04 Mar 2004 04:57:43 GMT, "Seeker" <do*******@me.here> wrote:

"Sarah" <no***********@zhouse.com> wrote in message
news:1s********************************@4ax.com.. .
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..


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

Thank you... that's very helpful...
Jul 20 '05 #3
On Thu, 04 Mar 2004 04:49:48 GMT, Sarah <no***********@zhouse.com> wrote:

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


[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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #4

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Thu, 04 Mar 2004 04:49:48 GMT, Sarah <no***********@zhouse.com> wrote:

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


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

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.
Jul 20 '05 #5
On Thu, 04 Mar 2004 12:21:56 GMT, Richard Formby <rf***@cueword.com.au>
wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
[mimicking context menu functionality]
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.


This has been discussed here a number of times before.


I know. I think I even commented at the last occasion.
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.


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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #6
Ivo
People wrote:
[mimicking context menu functionality]
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.


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.

In IE you can write to the clipboard using
somevariable.execCommand("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
Jul 20 '05 #7
Ivo wrote:
<snip>
In IE you can write to the clipboard using
somevariable.execCommand("Copy");
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:- queryCommandSupported,
queryCommandEnabled.)

<snip> ... . Rightclick once and you get some silly options,
rightclick again and you get the default menu!


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.
Jul 20 '05 #8
Richard Cornford wrote:
Ivo wrote:
In IE you can write to the clipboard using
somevariable.execCommand("Copy");
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).
... . Rightclick once and you get some silly options,
rightclick again and you get the default menu!

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).
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).
After all, if it is based on
code by Yep


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.
Jul 20 '05 #9
Yann-Erwan Perio wrote:
Richard Cornford wrote:

<snip>
(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.

<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.
Jul 20 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Sergio Otoya | last post: by
4 posts views Thread by Jon Asher | last post: by
3 posts views Thread by Mateusz Rajca | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.