Sharing a Page using JavaScript Object Model



Last week I was given a task to implement Share functionality using client side scripts. First I tried to search on the blogs but I didn’t find anything. So, I used IE developer tool to find out how SharePoint is calling Share from ribbon but no luck with it also. But I’m able to find the JavaScript function called on the click of “Shared With”. That is in Sharing.js that’s the main breakthrough. I opened the Sharing.debug.js to find out functions defined in that file. Then I find the function “DisplaySharingDialog (webUrl, listId, listItemId)” that is used to open the dialog box for sharing users.

function SharePage(){
EnsureScriptFunc('sharing.js', 'DisplaySharingDialog', function () {
DisplaySharingDialog(_spPageContextInfo.webAbsoluteUrl, _spPageContextInfo.pageListId, _spPageContextInfo.pageItemId.toString());
                });
}
Since this function is defined in Sharing.js file that why we are trying to ensure that Sharing.js is already loaded before calling DisplaySharingDialog function.

There are many other functions also in sharing .js for example
DisplaySharedWithDialog (webUrl, listId, listItemId, forceReadOnly, hideInviteLink)
which is used for displaying Shared With dialog box.

Hope this information is helpful to peoples facing the same problem as I was during this task.

Comments

Popular posts from this blog

Installation and Configuration of Office Online Server with SharePoint 2019

Workflow Manager 1.0- Installation, Configuration and Issues

SharePoint 2019 Upgrade Part 6: SharePoint Upgrade Issues