put text in Office Clipboard

Discussion in 'Javascript' started by Coder, Nov 20, 2004.

  1. Coder

    Coder Guest

    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.
     
    Coder, Nov 20, 2004
    #1
    1. Advertising

  2. Coder

    Tammo Guest

    "Coder" <> wrote in message
    news:...
    > 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.--
     
    Tammo, Nov 20, 2004
    #2
    1. Advertising

  3. Coder

    Randy Webb Guest

    Coder wrote:
    > 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)

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq
     
    Randy Webb, Nov 20, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    770
  2. Dan Bishop
    Replies:
    0
    Views:
    237
    Dan Bishop
    Aug 26, 2008
  3. Replies:
    4
    Views:
    271
    Randy Webb
    Dec 14, 2004
  4. Mahsha

    Clipboard - Copy Image To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    1
    Views:
    588
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
  5. Mahsha

    Clipboard - Copy Text To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    3
    Views:
    655
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page