How can I share image in facebook in firefox of using javascript?

[亡魂溺海] 提交于 2019-12-13 18:57:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!