copying a string to clipboard in IE4

B

buildmorelines

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>
 
M

Michael Winter

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
 
R

Randy Webb

buildmorelines said:
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.
 
B

buildmorelines

Michael Winter said:
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).
 
M

Michael Winter

[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
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top