How to add a link(Custom action) to a document library page's Ribbon with java script. And where to add that java-script? please help.

1 Answer 1


You can add the Ribbon Button using JavaScript API. You need to add the script in Content Editor or Script Editor Web Part

    var context = new SP.ClientContext.get_current();
this.site = context.get_web();
var customAction = this.site.get_userCustomActions().add();

var uiExtension = '<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">' +
                        '<CommandUIDefinitions>' +
                            '<CommandUIDefinition Location="Ribbon.ListForm.Edit.Commit.Controls._children">'+
                                '<Button Id="Ribbon.Documents.New.RibbonTest" '+
                                        'Command="PrintPage" '+
                                        'Sequence="0" '+
                                        'Image16by16="/_layouts/images/NoteBoard_16x16.png" '+
                                        'Image32by32="/_layouts/images/NoteBoard_32x32.png" '+
                                        'Description="Uses the notification area to display a message." '+
                                        'LabelText="Notify hello" '+
                                        'TemplateAlias="o1"/>' +
                            '<CommandUIHandler Command="PrintPage" '+
                                'CommandAction="javascript:SP.UI.Notify.addNotification(\'Hello from the notification area\');" />'+





context.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
        Function.createDelegate(this, this.onFailure)); 

SP.UserCustomActionCollection Class

Please refer the Link

Or else simply you can use SharePoint Designer to add the Custom Ribbon Action using SPD2013

  • i am trying to add this code in content editor in a document library page. But after adding the code, even the ribbon stops appearing in the page. Same is with script editor web part. Nov 8, 2017 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.