put text in Office Clipboard

C

Coder

Hi,

I wanted to know of a way that I can put text into the Office
(Outlook/Word) clipboard from Internet Explorer.

So when a user a user clicks on a button, some text is placed into the
clipboard.

Ive tried this, but no luck.

<script language="javascript">
function cpy(myString){
if((typeof window.clipboardData != 'undefined')&&
(window.clipboardData.setData)){
alert('setting: ' + myString);
res = window.clipboardData.clearData();//("text",myString);

alert(res);
}
else {
alert('null');
}
}
</script>

- Thanks.
 
T

Tammo

Coder said:
Hi,

I wanted to know of a way that I can put text into the Office
(Outlook/Word) clipboard from Internet Explorer.

So when a user a user clicks on a button, some text is placed into the
clipboard.

Ive tried this, but no luck.

<script language="javascript">
function cpy(myString){
if((typeof window.clipboardData != 'undefined')&&
(window.clipboardData.setData)){
alert('setting: ' + myString);
res = window.clipboardData.clearData();//("text",myString);

alert(res);
}
else {
alert('null');
}
}
</script>
You need a textarea or similar to temporarily hold your string.

// with <TEXTAREA ID="taCode" STYLE="display:none;"></TEXTAREA> in the body
// will copy the element with the given ID, or the selection if there is one
function copy2clipboard(t) {
taCode.innerText =
'\n'+(isselect()?isselect():document.getElementById(t).innerText);
textRange = taCode.createTextRange();
textRange.execCommand("RemoveFormat");
textRange.execCommand("Copy");
}
function isselect(){
if (document.getSelection) { return document.getSelection(); } // if IE4+
if (document.selection && document.selection.createRange) { return
document.selection.createRange().text; } // if NS
return false;
}
// to read the clipboard, use window.clipboardData.getData("Text");

http://4umi.com/web/javascript/

Hope this helps
Tammo.--
 
R

Randy Webb

Coder said:
Hi,

I wanted to know of a way that I can put text into the Office
(Outlook/Word) clipboard from Internet Explorer.

So when a user a user clicks on a button, some text is placed into the
clipboard.

Ive tried this, but no luck.

<script language="javascript">
function cpy(myString){


if (window.clipboardData)
window.clipboardData.setData('text', myString)
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top