Three.js dom id of the canvas element used for webgl renderer

I would like to get the identifier of a canvas element automatically created using three .js.

Alternatively, I would be equally happy (perhaps more than that) with the ability to walk along an existing canvas element id at build time.

After researching, I tried this:

renderer = new THREE.WebGLRenderer( { canvas: my_canvas } );

without success (this is from a rather old build, but hoped it would work). Perhaps some parameter syntax has changed from 2 years ago?

(my_canvas, being the identifier of the canvas, also tried to walk through the context, no luck)

Finally, I tried:

document.getElementsByTagName('canvas');

which returned nothing ... it was a puzzle and the notorious straw that made me publish here.

Any insight appreciated, thanks! (I now have voting rights)

+5
2
var canvas = document.getElementById("canvasID");
renderer = new THREE.WebGLRenderer({ canvas: canvas });
+15

(r57) three.js/src/renderers/WebGLRenderer.js( ), , canvas . , . , , , , jsfiddle, .

+4

All Articles