Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    copy rendered table HTML to Clipboard, not Text

    Hello, and thank you for taking the time to read this.

    I have an issue where I am trying to allow the user to click on a table and automatically copy a table into the clipboard. I do this with text using IE:

    function clickCopyText(fi) {
    window.clipboardData.setData("Text",fi.innerText);
    }

    so to copy the table, I tried:
    function clickCopyHTML(fi) {
    window.clipboardData.setData("Text",fi.innerHTML);
    }


    The Trouble with Tables is the HTML itself gets copied as opposed to the rendered table. I am probably looking at some other way of getting the code to the clipboard, but I am stymied. I can do it with images, but not with rendered HTML.

    Any help or information would be greatly appreciated. Thanks again for taking the time to read.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You probably could have found this solution searching for innerText Firefox on your favorite search engine:

    Code:
    var text = "";
    if(elem.textContent){
        text = fi.textContent;
    }
    else{
        text = fi.innerText;
    }
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Eric,

    Isn't that code for getting the equivalent of innerText in Firefox? Does that transfer rendered HTML to the clipboard using IE? I can't seem to make it work.

    Thanks for your reply.

  • #4
    Banned
    Join Date
    Mar 2009
    Posts
    248
    Thanks
    3
    Thanked 68 Times in 66 Posts
    I'm not certain about this, but I believe it works in IE:

    Code:
    var ctrlRange = document.body.createControlRange();
          		ctrlRange.add(document.getElementById('tableId'));
    		ctrlRange.execCommand("Copy");
    Change 'tableId' to the actual ID of the table:

    Code:
    <table id='myTable'>

  • Users who have thanked 12 Pack Mack for this post:

    mrgr8avill (06-29-2009)

  • #5
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Didn't work on IE7, but it got me going in the right direction. What ended up working was:

    var div = document.getElementById('divID');
    div.contentEditable = 'true';
    var controlRange;
    if (document.body.createControlRange) {
    controlRange = document.body.createControlRange();
    controlRange.addElement(div);
    controlRange.execCommand('Copy');
    }
    div.contentEditable = 'false';

    THANKS!!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •