windows-phone-8.1winjs

Social sharing in Winjs application


I'm trying to add social sharing funtionallity (facebook, mail, etc) to my winjs application, but can't find the built in functionallity for it.

In a C#/ VB app, there is ShareLinkTask, but I can't find it for winjs. It should be possible since winjs can access phone functionallity.


Solution

  • You have to get the DataTransferManager for the current view first and add a listener to datarequested event. When this event triggers you can specify what data you want to share.

    var dataTransferManager =
            Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
    dataTransferManager.addEventListener("datarequested", dataRequested);
    ...
    function dataRequested(e) {
        var request = e.request;
        request.data.properties.title = 'a title';
        request.data.setText('Some text');
    };
    

    More on this sample here...

    To show the share functionality from anywhere in your app just add a handler for the click event to an element and show the UI.

    document.getElementById("share").addEventListener("click", function () {
        Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI();
    }, false);
    

    All info you need to share other things, like HTML can be found at the MSDN.