Sharepoint Insight by Namwar Rizvi

Sharepoint Tips, Tricks and inside knowledge from real world experience by Namwar Rizvi

Add Custom context menu by Javascript in SharePoint

Posted by namwar on February 19, 2009


If you want to add a custom menu item in Document Library’s item context menu just by Javascript without going into the details of ¬†adding any new feature or writing your own assembly then here is a quick trick:

  1. Add a new Content Editor Web Part on your target page
  2. Open the tool pane of the web part
  3. Click Source Editor and add following Javascript code in it
    <script language="javascript">
    function Custom_AddDocLibMenuItems(m, ctx)
    {
      var strDisplayText = "Say Hello World!";
      var strAction = "alert('Hello World')";
      var strImagePath = "";
     
      // Add our new menu item
      CAMOpt(m, strDisplayText, strAction, strImagePath);
     
      // add a separator to the menu
      CAMSep(m);
     
      // false means that the standard menu items should also be rendered
      return false;
    }
    </script>
    
  4. Click Save
  5. Click OK in toolpane to close it
  6. Now open the context menu of an item of the document library and you will see your new menu item in it similar to following

javascript-custom-menu

Please note that this menu item will only be visible on your target not on every page of your document libraries.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: