canvas-snapshot.js 505 B

123456789101112131415161718
  1. /* Replace canvas with image snapshot
  2. */
  3. (function(){
  4. var canvas = document.querySelectorAll ("canvas");
  5. for (var i = 0; i < canvas.length; i++) {
  6. var c = canvas[i];
  7. var data = c.toDataURL ();
  8. var parent = c.parentNode;
  9. var img = document.createElement ('img');
  10. /* copy all attributes */
  11. for (var i = 0; i < c.attributes.length; i++) {
  12. var attr = c.attributes.item(i);
  13. img.setAttribute (attr.nodeName, attr.nodeValue);
  14. }
  15. img.src = data;
  16. parent.replaceChild (img, c);
  17. }
  18. }());