javascript - Copy HTML table structure to clipboard -
im looking advice on this. ive been looking trough internet possible solutions on how copy html table structure it's text clipboard no lucky far.
what have @ moment simple table data , users need copy email using outlook , when copy/paste it. pasting manually outlook show table structure , text rendered correctly. issue users have several large tables making clumsy copy , scroll down @ same time reach bottom of page.
so looking simple button automatically. looking find main div container , copy of table structures , text within user's clipboard. found popular solution called zeroclipboard copies text , not actual html table structure it.
would know if possible accomplish jquery or other addons? appreciate advice on this.
i don't think can trigger copy event button, suggestion workaround: clipboard api allows set custom data on copy event. listen copy
event on table , send html
text instead. user triggering copy event table html
(or whichever text want) in clipboard instead.
in snippet example below select text , copy it:
document.getelementbyid('sample').addeventlistener('copy', function (e) { var html_data = document.getelementbyid('sample').innerhtml; document.getelementbyid('result').textcontent = html_data; e.clipboarddata.setdata('text/plain', html_data); e.preventdefault(); });
span { color: red; }
<div id='sample'> <div style="padding-bottom: 5px;">select of text , copy clipboard using ctrl+c or right-click+copy.</div> </div> <div >the content of clipboard is: <span id="result"></span></div>
doc clipboard api: http://www.w3.org/tr/clipboard-apis/
and caniuse: http://caniuse.com/#feat=clipboard
Comments
Post a Comment