Requirement Overview
SPS provides some default menus when you browse the documentation library on the SPS documentation library website. The default menu provided by the system can basically meet the general needs, but sometimes you need to add your own menu items.
Default menu
Custom menu
Menu item click Effect
Implementation Principle
In the ows. js file on the server side, we can see the following:CodeSegment
Function adddoclibmenuitems (M, CTX)
{
If (typeof (custom_adddoclibmenuitems )! = "Undefined ")
{
If (custom_adddoclibmenuitems (M, CTX ))
Return;
}
// Others
Custom_adddoclibmenuitems (M, CTX) is the interface provided by SPS for us.
Details
(1) edit a script to be added to the client.
<Script language = "JavaScript">
Function custom_adddoclibmenuitems (M, CTX)
{
VaR strdisplaytext = "watch a movie together at night, OK? "; // Display text of the menu item
VaR straction = "alert ('No, don't want to go with you! ') "; // The actual function of the menu item
VaR strimagepath = ""; // display image of the menu item
// Add the menu item to the context menu
Camopt (M, strdisplaytext, straction, strimagepath );
// Add a separator bar
Camsep (m );
// If true, the default menu item is not displayed.
// If it is fasle, the default menu item is displayed.
Return true;
}
</SCRIPT>
(2) Add the custom Javascript script to the page
Browse to the document library website that needs to be added to the custom menu
"Modify shared web page" => "add Web parts" => "Browse"
Drag "content edit web parts" to the page
Select modify shared Web parts"
In "layout", remove the "display on web page" check box
Click the "source editor..." button to add the completed export cirpt script to the dialog box and save it.
Now, click the context menu of the document library file to view only the menu items you have added.