问题
I have an image generated from canvas.
var image = canvas.toDataURL("image/png");
Now I want to share it in facebook. How can I do it for firefox os using javascript. I am very new. I search a lot but unfortunately I did not get any results.
回答1:
To share your image is recommended to use the WebActivities allowing you to interact with other applications, for example, share a picture or text ...
Below I leave a simple code to implement it and share your image, you must specify that it is an image and pass it as a blob.
blobCanvas.width = imgToShare.width;
blobCanvas.height = imgToShare.height;
// Get context and draw image
var blobCanvasContext = blobCanvas.getContext("2d");
blobCanvasContext.drawImage(imgToShare, 0, 0);
// Export to blob and share through a Web Activitiy
blobCanvas.toBlob(function (blob) {
new MozActivity({
name: "share",
data: {
type: "image/*",
number: 1,
blobs: [blob]
}
});
});
I recommend you read more about WebActivities in the MDN
来源:https://stackoverflow.com/questions/22682254/how-can-i-share-image-in-facebook-in-firefox-of-using-javascript