clip board data as html

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SirCodesALot

    clip board data as html

    hi all,

    I am trying to copy the contents of a div to the clip board the same
    way that Microsoft copies it when you select the contents with the
    mouse and select copy. However, something is not the same.

    here is the code simplified:
    var s = document.getEle mentById("testD iv").innerHTM L;
    if( window.clipboar dData && clipboardData.s etData )
    {
    clipboardData.s etData("text", s);
    }

    If I use this method to copy to clipboard, then to Word, i get:
    <TABLE><TBODY>< TR><TD>text</TD></TR></TBODY></TABLE>

    however, if I select the table with the mouse, select copy, and paste
    in to word, the actual table shows up like it did in the web page.

    Any way to make the clipboard put the html in the correct format that
    word wants?

    Thanks,
    -Scott
  • Evertjan.

    #2
    Re: clip board data as html

    SirCodesALot wrote on 30 mei 2008 in comp.lang.javas cript:
    hi all,
    >
    I am trying to copy the contents of a div to the clip board the same
    way that Microsoft copies it when you select the contents with the
    mouse and select copy. However, something is not the same.
    >
    here is the code simplified:
    var s = document.getEle mentById("testD iv").innerHTM L;
    Try IE only:

    var s = document.getEle mentById("testD iv").innerTex t
    if( window.clipboar dData && clipboardData.s etData )
    {
    clipboardData.s etData("text", s);
    }
    >
    If I use this method to copy to clipboard, then to Word, i get:
    <TABLE><TBODY>< TR><TD>text</TD></TR></TBODY></TABLE>
    >
    however, if I select the table with the mouse, select copy, and paste
    in to word, the actual table shows up like it did in the web page.
    >
    Any way to make the clipboard put the html in the correct format that
    word wants?
    >
    Thanks,
    -Scott


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • SirCodesALot

      #3
      Re: clip board data as html

      On May 30, 2:32 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
      SirCodesALot wrote on 30 mei 2008 in comp.lang.javas cript:
      >
      hi all,
      >
      I am trying to copy the contents of a div to the clip board the same
      way that Microsoft copies it when you select the contents with the
      mouse and select copy.  However, something is not the same.
      >
      here is the code simplified:
      var s = document.getEle mentById("testD iv").innerHTM L;
      >
      Try IE only:
      >
      var s = document.getEle mentById("testD iv").innerTex t
      >
      >
      >
      >
      >
      if( window.clipboar dData && clipboardData.s etData )
           {
                clipboardData.s etData("text", s);
          }
      >
      If I use this method to copy to clipboard, then to Word, i get:
      <TABLE><TBODY>< TR><TD>text</TD></TR></TBODY></TABLE>
      >
      however, if I select the table with the mouse, select copy, and paste
      in to word, the actual table shows up like it did in the web page.
      >
      Any way to make the clipboard put the html in the correct format that
      word wants?
      >
      Thanks,
      -Scott
      >
      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)- Hide quoted text -
      >
      - Show quoted text -
      thanks for your reply, that does work, but it drops all the formating
      for the tabels. When you selected with content with the mouse and do a
      copy, MS must be saving other information about the formating for the
      table.

      Comment

      • SirCodesALot

        #4
        Re: clip board data as html

        On May 30, 4:11 pm, SirCodesALot <sjour...@gmail .comwrote:
        On May 30, 2:32 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
        >
        >
        >
        >
        >
        SirCodesALot wrote on 30 mei 2008 in comp.lang.javas cript:
        >
        hi all,
        >
        I am trying to copy the contents of a div to the clip board the same
        way that Microsoft copies it when you select the contents with the
        mouse and select copy.  However, something is not the same.
        >
        here is the code simplified:
        var s = document.getEle mentById("testD iv").innerHTM L;
        >
        Try IE only:
        >
        var s = document.getEle mentById("testD iv").innerTex t
        >
        if( window.clipboar dData && clipboardData.s etData )
             {
                  clipboardData.s etData("text", s);
            }
        >
        If I use this method to copy to clipboard, then to Word, i get:
        <TABLE><TBODY>< TR><TD>text</TD></TR></TBODY></TABLE>
        >
        however, if I select the table with the mouse, select copy, and paste
        in to word, the actual table shows up like it did in the web page.
        >
        Any way to make the clipboard put the html in the correct format that
        word wants?
        >
        Thanks,
        -Scott
        >
        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)- Hide quoted text -
        >
        - Show quoted text -
        >
        thanks for your reply, that does work, but it drops all the formating
        for the tabels. When you selected with content with the mouse and do a
        copy, MS must be saving other information about the formating for the
        table.- Hide quoted text -
        >
        - Show quoted text -
        I found a way to do it in IE:
        function copyDivToClipbo ard(divId) {
        var range = document.create Range();
        range.selectNod e(document.getE lementById(divI d));
        window.getSelec tion().removeAl lRanges();
        window.getSelec tion().addRange (range);

        try
        {
        range.execComma nd("Copy");
        }
        catch (e)
        {
        alert("Sorry, your browser does not support this feature. Please
        right click the highlighted text and select 'copy'.")
        }
        }

        Comment

        • Holger Jeromin

          #5
          Re: clip board data as html

          SirCodesALot schrieb am 30.05.2008 23:11:
          On May 30, 2:32 pm, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
          >SirCodesALot wrote on 30 mei 2008 in comp.lang.javas cript:
          thanks for your reply, that does work, but it drops all the formating
          for the tabels. When you selected with content with the mouse and do a
          copy, MS must be saving other information about the formating for the
          table.
          The Clipboard in Windows is capable to host multiple information
          simultanously.

          Text only+HTML coded version

          A Texteditor used the textonly, while Word is able to recognise the HTML
          design.

          Try in Word "edit/paste special..." to see what is in there.

          --
          Mit freundlichen Grüßen
          Holger Jeromin

          Comment

          Working...