
This menu is executed with the help of a JavaScript file located in "C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\OWS.js.
The OWS.js file is the java script file that implements the functionality for the context menu. OWS.js also lets users to implement custom menu options that can be used to create a custom menu in the context menu. Changes made to the OWS.js java script file is implemented or reflected across all the applications in the server farm.
Alternatively, a content editor web part can be used to implement the same if the context menu is required only in a particular site collection.
Steps:
1. Go to Edit Page for the page or site for which you want to display the context menu.

2. Add a content editor web part for the library or the list for which the context menu needs to be applied.

3. Click on the link that says open the tool and pane which opens up the tool pane. In the Source Editor Web part add the following JavaScript code to add custom menu for a Document Library within the script tag.
function Custom_AddDocLibMenuItems(m, ctx)
{
var strDisplayText = "Navigate to Google";
var strAction = "STSNavigate('http://www.google.com')";
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;
}

4. Save the script and check the Hidden option in the Layout section of the tool pane.
5. The context menu will be visible now.

6. In order to add a custom context menu for a Document Library, implement the custom functionality using the Custom_AddDocLibMenuItems function and in order to add a custom context menu for a list, implement the custom functionality using the Custom_AddListMenuItems function.