1

When calling cloneNode() on a DOM node with a <canvas> child, the canvas content doesn't get cloned.

Is there a way to tell cloneNode() to clone the canvas contents as well, or maybe modify the canvas node in such way that the contents will get cloned?

Tzach
  • 12,889
  • 11
  • 68
  • 115
  • https://stackoverflow.com/questions/3318565/any-way-to-clone-html5-canvas-element-with-its-content –  Mar 06 '18 at 18:09
  • @doodlemeister this doesn't answer my question, since I'm using `cloneNode` on a parent of the canvas, and don't have access to the canvas itself. – Tzach Mar 06 '18 at 18:14
  • I'm confused. You're saying that you call `cloneNode`, but below you're saying that 3rd party code calls it. Is the situation that a 3rd party clones some ancestor of your canvas, which fails to clone it? If so, there's probably little you can do except to contact that vendor and have them add special handling for `canvas` elements when cloning. –  Mar 06 '18 at 19:15

1 Answers1

0

Sorry, this was wrong. See the duplicate.

The true argument to the function instructs it to deeply clone the element.

var clone = canvas.cloneNode(true);

  • In my case `cloneNode` is actually called with `true` (by a third party package which I can't control). – Tzach Mar 06 '18 at 18:10