By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,313 Members | 2,798 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,313 IT Pros & Developers. It's quick & easy.

copying a string to clipboard in IE4

P: n/a
I need a utility that will basically add a "Copy OnClick Event" to my
right click context menu in Internet Explorer IE. I am a super newbie
in javascript. The following code works for IE5, but not for IE4,
which doesnt have setdata, getdata, etc. methods for dealing with the
clipboard. The folowing code is invoked by a registry context menu
entry. When I looked at IE4's copy system uses execcommand, it only
works on something that is selected as far as I can see, I dont have
anything selected, because user isnt going be highlighting, and that
wont get the onclick attribute value. All I have is a variable string
in javascript with what I need to get into the clipboard. How can I
make this code work in IE4, so I dont need to force users to get IE5?

<SCRIPT LANGUAGE="JavaScript">
var clipRes;

var parentwin = external.menuArguments;
var doc = parentwin.document;
var actele = doc.activeElement;
var attrib = actele.attributes;
var oc = attrib.onclick;
var str = oc.nodeValue;

alert(str);
clipRes = parentwin.clipboardData.setData("Text",str);
alert(clipRes);

</SCRIPT>
Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 25 Nov 2004 08:25:27 -0800, buildmorelines <bu****@hotmail.com> wrote:
How can I make this code work in IE4, so I dont need to force users to
get IE5?
You can't. The best you can do is test for support before executing the
code (preferably before adding the item) so that you don't trigger errors.

if(window.clipboardData) {
// object supported
}

would do.
<SCRIPT LANGUAGE="JavaScript">


The language attribute has been deprecated for over six years. Use the
(required) type attribute, instead:

<script type="text/javascript">

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2

P: n/a
buildmorelines wrote:
I need a utility that will basically add a "Copy OnClick Event" to my
right click context menu in Internet Explorer IE. I am a super newbie
in javascript. The following code works for IE5, but not for IE4,
which doesnt have setdata, getdata, etc. methods for dealing with the
clipboard. The folowing code is invoked by a registry context menu
entry. When I looked at IE4's copy system uses execcommand, it only
works on something that is selected as far as I can see, I dont have
anything selected, because user isnt going be highlighting, and that
wont get the onclick attribute value. All I have is a variable string
in javascript with what I need to get into the clipboard. How can I
make this code work in IE4, so I dont need to force users to get IE5?


Apart from what has already been said. If IE4 can copy selected text,
then you can set the value of an input to the string you have, select it
all, then copy it to the clipboard.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3

P: n/a
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:<opsh04pbjex13kvk@atlantis>...
On 25 Nov 2004 08:25:27 -0800, buildmorelines <bu****@hotmail.com> wrote:
How can I make this code work in IE4, so I dont need to force users to
get IE5?


You can't. The best you can do is test for support before executing the
code (preferably before adding the item) so that you don't trigger errors.

if(window.clipboardData) {
// object supported
}

would do.
<SCRIPT LANGUAGE="JavaScript">


The language attribute has been deprecated for over six years. Use the
(required) type attribute, instead:

<script type="text/javascript">

[snip]

Mike

Is there any ActiveX control I could use to control the clipboard from
IE4, the security zone inside the context menu script is low enough to
use Wscript.Shell control?

There was also some code about making a hidden value in the document
then creating a textrange on it, and then execcommand('copy') or
something, but since the javascript code isnt exactly running in the
original webpage window it doesnt seem to work (I did change it to
refer to the window object of the original page).
Jul 23 '05 #4

P: n/a
On 25 Nov 2004 17:56:00 -0800, buildmorelines <bu****@hotmail.com> wrote:

[snip]
Is there any ActiveX control I could use to control the clipboard from
IE4, the security zone inside the context menu script is low enough to
use Wscript.Shell control?


I'm afraid I couldn't say.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.