Use JavaScript to customize SharePoint Document Library/list item menu

Source: Internet
Author: User
Custom menus in SharePoint are usually implemented by feature with customaction, for example, hiding a menu: < Hidecustomaction >
Groupid = "text"
Hideactionid = "text"
Id = "text"
Location = "text">
</ Hidecustomaction >

Customize a menu: < Customaction
ID = "Extend"
Location = "Microsoft. Sharepoint. Administration. applicationmanagement"
Sequence = "10"  
Title = "Extend or upgrade virtual server"  
Description = "" >
< Urlaction URL = "Vslist. aspx? Nextpage = extendvsoption. aspx & amp; show = needextend & amp; show = needupgrade" />
</ Customaction >

For more information, see the SDK or related online.Article.
But .... This method does not work. For example, if I want to change an item in the menu of the document library or listitem in the list or add or delete a menu, this method will not work ......

At this time, it is very easy to implement through javascript. If you have read the core. jsCodeWe will find that Ms has reserved custom interfaces for us to implement our own menu definition. What Ms wants is thoughtful ......
Core. JS is under 1033 [English] Or 2052 [Chinese] Under path c: \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template \ layouts, find the function for adding the document library/list menu.

As you can see, We can customize custom_adddoclibmenuitems (Document Library)/custom_addlistmenuitems (list) to add our own menus. The specific method is...
1) Add a webpart-Content Editor widget to our page and modify the widget attributes. It is best to set the widget to hidden:


Click "Source editor..." And enter our custom Javascript script to implement our own menu: < Script Language = " Javascript " >
Function Custom_adddoclibmenuitems (M, CTX)
{
Strdisplaytext =   " My menu " ;
VaR Rootmenu = Casubm (M, strdisplaytext, "" , "" , 500 );

Strdisplaytext =   " My menu or my menu " ;
Straction =   " Stsnavigate ('HTTP: // www.cnblogs.com ') " ;
Strimagepath = CTX. imagespath + " Oisweb.gif " ;
Menuoption = Camopt (rootmenu, strdisplaytext, straction, strimagepath );
Menuoption. ID =   " Id_mysubmenu " ;
Return   False ;
}
</ Script >

For details about how to write a function, refer to the core. js statement: Return false at the end. This indicates that the system code will continue to be executed, if return true... The entire menu is just your own menu item. Save the file and exit the editing mode:

If I want to remove a menu, such as workflow, I am stupid. I used a stupid method to copy the script in his built-in adddoclibmenuitems and comment out the menu items to be removed, then return true.

Personal habits:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.