Xylos brands

SharePoint - Show the Share Action on your Page Layouts

A question I received a while ago was if it would be possible to display the share action on a page like the action in the context menu of that page.

[caption id="" align="aligncenter" width="324"]Share Action Share Action[/caption]

Solution

The solution for this is really simple, all you need to do is creating a hyperlink on the page layout and use a JavaScript function call in the href attribute for the click event.

<a href="javascript:sharePage()" title="Share page">Share this page</a>

The function behind this call looks like this:

function sharePage() {
  EnsureScriptFunc("sharing.js", "DisplaySharingDialog", function () {
    var webUrl = _spPageContextInfo.webAbsoluteUrl;
    var listId = _spPageContextInfo.pageListId;
    var itemId = _spPageContextInfo.pageItemId;
    if (typeof webUrl !== "undefined" && typeof listId !== "undefined" && typeof itemId !== "undefined") {
      DisplaySharingDialog(webUrl, listId, itemId.toString());
    }
  });
}

This function doesn't require a lot of code. You'll just need to be sure that the DisplaySharingDialog function is available, and pass through the following parameters:

  • The current URL of the site;
  • The list ID of the current page;
  • The item ID of the current page.

As you can see in the code, these things can be resolved from the _spPageContextInfo object.

* Originally posted to: http://www.eliostruyf.com/show-the-share-action-on-your-page-layouts/ *

Share this blogpost

Also interesting for you

Leave a reply

Your email address will not be published. Required fields are marked.