Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  69] [ 7]  / answers: 1 / hits: 19271  / 12 Years ago, fri, november 2, 2012, 12:00:00

I'm using Fabric.js and I've created a fabric canvas object at one place.



var x = new fabric.Canvas(mycanvas);


Now at another place, I want to access this object where 'x' won't be available. So how can I get the same fabric canvas object.



I don't wanna change the scope of x or pass x as arg.



Also, how to get the toDataURL from the fabric canvas object?


More From » jquery

 Answers
39

Assuming that mycanvas is the ID of a Canvas element, you could store the reference to the fabric object on the Canvas element itself:



var x = new fabric.Canvas(mycanvas);
document.getElementById(mycanvas).fabric = x;


You can then retrieve that object any time you want with:



var y = document.getElementById(mycanvas).fabric;
var url = y.toDataURL(png, 1);

[#82234] Wednesday, October 31, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;