SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a custom delete page button for my users on a publishing site that resides on the actual page. At first I thought it would be as simple as just copying the code behind the 'Delete Page' link in the ribbon, but unfortunately it's not that simple. It looks like the Delete Page link generates some custom JS on the fly and I can't seem to track it down. I created custom buttons for 'add new page' and 'edit page' which were pretty easy.

If anyone can give me some pointers it would be much appreciated!

share|improve this question
up vote 7 down vote accepted

To clarify: I assume that you have a document library with pages in it, and you intend to reimplement "Delete document" ribbon button functionality:

delete document ribbon button

One of the approaches could be to get selected item using SP.ListOperation.Selection.getSelectedItems(), and then use SharePoint Client Object Model to delete it. This is an intended approach.

But also it's possible to achieve the objective using original SharePoint code for 'Delete document' ribbon button. I've done some investigations and found a working solution. But be aware: although it was an interesting exploration, the functionality is undocumented.

So, actually, you're right. Desired code is hidden deeeeep in SharePoint ribbon javascript. Here is the callstack, check it out:


So you could notice SP.Ribbon.PageManager.executeRootCommand method call here, and maybe you can try to use it (it is documented and supported), but I was disappointed with the number of parameters of this method and decided to dive even deeper. Because I know undoubtedly, that deletion of a selected item is a very simple operation and all necessary information for the deletion could be retrieved from some page context or global variables or smth like this.

So I came down to the last handleCommand method and then I saw this picture:


Woohoo, here it is, DeleteSelectedItems, with a context variable passed into it. After a bit of further investigations, I've found out, that this context could be retrieved with the function SP.Ribbon.NativeUtility.getCtxForView, which gets as a parameter the current list view GUID.

Unfortunately, current list view GUID is hardcoded into the page layout (that's because there could be several views on the same page), so I suppose you could turn the actual view ID into your button code on the server side, then rendering the javascript.

So, finally solution is compressed to following js call:


I tried this in IE javascript console for my particular test view:


and it works! :)

result screenshot

And after I pressed OK, it actually deleted the selected item.

So, I hope you enjoyed the adventure :)

share|improve this answer
Nice work digging this out! You should be able to get the current view context from ctx.view, so: DeleteSelectedItems(SP.Ribbon.NativeUtility.getCtxForView(ctx.view)); – Jussi Palo Oct 14 '13 at 9:00

If you want a page to be able to delete itself (in other words the user clicks a button on the actual page they want deleted), you should be able to just use:


Just be sure to redirect the user to a different page, because they will see a 404 error since the page will no longer exist.

share|improve this answer
Doesn't seem to do anything, except complain that SPContext is not defined. – Jussi Palo Nov 18 '14 at 13:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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