"Coder" <im************@gmail.com> wrote in message
news:7e**************************@posting.google.c om...
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.getElementByI d(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.--