Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function createCSV(selector){
  2. var contentString, $els, i,j, l,m, tmp,
  3. row = document.querySelectorAll(selector)
  4.  
  5. for(i=0, l=$row.length; i<l; i++){
  6. $els = $row[i].children;
  7. tmp = [];
  8. for(j=0, m=$els.length; j<m; j++){
  9. tmp.push($els[j].innerText);
  10. }
  11. contentString += tmp.join(",")+"\n";
  12. }
  13. return contentString;
  14. }
  15. function download(data, opt){
  16. var a = window.document.createElement('a');
  17. a.href = window.URL.createObjectURL(new Blob([data], {type: opt.mimeType}));
  18. a.download = opt.filename;
  19. document.body.appendChild(a)
  20. a.click();
  21. document.body.removeChild(a)
  22. }
  23.  
  24. download(createCSV("table tr"), {
  25. mimeType:'text/csv',
  26. filename: 'table.csv'
  27. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement