Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

i want to hide sharepoint 2010 list/library context menu based on users.

i am using below javascript

  $(document).ready(function(){      
        $('.ms-MenuUIPopupBody').live('blur', function() {       
           var elm = $("div.ms-MenuUIULItem a:contains('View in Browser')"); 
           elm.remove();     
           $("div.ms-MenuUIULItem a:contains('Edit in Browser')").remove();  
         });
  });

It is hiding menu only on focus or blur or mouse-over on the context menu.

the context menu is generating dynamically by core.js file

i need to add the script when the context menu is created.

so i need to find the event for context menu

enter image description here

how to find the click event and add my custom code.

with "Andrew" i found good solution and to handle the context menu event

var _MenuHtc_show;  

function OverrideMenuHtc_show()
{
   _MenuHtc_show = window.MenuHtc_show;
   window.MenuHtc_show= function (m,r,fr,ft,yoff) {
      _MenuHtc_show(m,r,fr,ft,yoff); 
      var elm = $(".ms-MenuUIULItem[text='Alert Me']");
      elm.remove();       
   };
}

ExecuteOrDelayUntilScriptLoaded(OverrideMenuHtc_show, "core.js")

its working fine but its hiding context menu for all webparts. i need to find the context menu selected webpart id to check is it right webpart to hide context menu.

i am able to find the webpart id after once i select webpart with this code.

 var listId = SP.ListOperation.Selection.getSelectedList();  

or

var ctxCur = GetCurrentCtx();
var SPGridViewGuid = ctxCur.listName;

but if i click on "v" symbol with out selecting the webparts its return null.

is there any way to find the context menu selected webpart id. so its solves my problem.

share|improve this question
    
Possible duplicate to: sharepoint.stackexchange.com/questions/66998/… –  Robert Lindgren Apr 30 '13 at 9:39
    
The context menu is security trimmed and only shows items based on permissions of the current user. Why do you want to hide it? It is just as easy to create a view that does not use this item and restrict some users to that view, but what business case are you trying to solve? –  spevilgenius Apr 30 '13 at 10:42
    
my client want to hide the ribbon buttons based on users or groups (not using list/library permissions), i am able to hide ribbon buttons. i am using javascript to hide the ribbon buttons but in context menu the option is still available so i need to hide in context menu also. ex:- if i hide the "alert me" in ribbon, the option is still available in context menu. so i want to extend the webpart to hide context menu also. –  kavalirakesh Apr 30 '13 at 10:55
    
i am using ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(RibbonresizeHandler); }, "SP.js"); function RibbonresizeHandler() { // do some action } to handle the ribbon. it will raise when ever the ribbon bar show or hide, i need to know some functionality to with context menu –  kavalirakesh Apr 30 '13 at 10:56
    
Please don't post the same question more than once. Edit your original question if you need to expand it. Thanks. [mod] –  SPDoctor Apr 30 '13 at 13:55
add comment

3 Answers 3

up vote 2 down vote accepted

What about that?

 $('.s4-ctx').css('display','none');

It will hide buttons that show context menu.


If you need to hide context menu only from web part with specified id you need to use:

$("div[webpartid='85c13a33-57a3-456b-a19b-c68c97756184'] .s4-ctx").css('display','none');

If you want to remove menu item, for ex. "Alert Me" add this script that overrides standard core.js function "MenuHtc_show" and hides menu item from context menu in specified webpart:

var _MenuHtc_show;  

function OverrideMenuHtc_show()
{
   _MenuHtc_show = window.MenuHtc_show;
   window.MenuHtc_show= function (m,r,fr,ft,yoff) {
      _MenuHtc_show(m,r,fr,ft,yoff); 
      var items = $("div[webpartid='85c13a33-57a3-456b-a19b-c68c97756184'] .ms-MenuUIULItem[text='Alert Me']");
      $(items).css('display','none');       
   };
}

ExecuteOrDelayUntilScriptLoaded(OverrideMenuHtc_show, "core.js")
share|improve this answer
    
it will hide context menu ("v") symbol so the full context menu not accessible. but i want hide only few context menu like "alert me", "edit properties" based on uses. i can add css to hide context menu like ".ms-MenuUIULItem[text='Edit Properties']{display:none !important;} " but the problem is it will hide context menu in entire page. if page contains 2 webparts it will applicable to all webparts in page. i want to hide context menu for individual webpart. so when i click ("v") symbol i need to identify the webpart guid and apply css with jquery. –  kavalirakesh Apr 30 '13 at 10:41
    
If you want to apply changes only to Web Part with specified id you could find Web Part's container using selector "div[webpartid='85c13a33-57a3-456b-a19b-c68c97756184']" and then apply your css to its child elements. I updated my answer. Hope it will help. –  Andrew Apr 30 '13 at 20:55
    
i understand the concept.this code hides the entire context menu. if you don't mind can you give me a small example to hide a child node of context menu. like can you give me a example to hide "alert me". it will very help full to me. –  kavalirakesh May 1 '13 at 8:35
    
I updated my answer. Is it fit for you? –  Andrew May 1 '13 at 10:16
    
excellent script, i checked the script with my webpartid, its raising when ever i chick the "v" symbol, but unfortunately its not hiding the "Alert Me". –  kavalirakesh May 1 '13 at 11:16
show 3 more comments

Any reason why you are not using a HideCustomAction?

Here is the MSDN for that.

And here is a resource for finding the correct groups

share|improve this answer
    
i want disable some functionalists to the users dynamically. like "alert me", "edit in browser" even though customer have permissions (exceptional users). i am able to hide ribbon buttons programmatically but in context menu the functionality is still available. i don't want remove his permissions but just hide the ribbon buttons and context menu. –  kavalirakesh Apr 29 '13 at 9:23
    
So to some users bu not all users? –  Robert Lindgren Apr 29 '13 at 9:24
    
exactly i need to show to some users hide to some users but dynamically. i am using user control as delegate control and adding the javascript dynamically so based on javascript the menu items will hide. i will extend the code to work based on users but in javascript the menu is hiding on mouse hove,but i need when open context menu it has to be hide. –  kavalirakesh Apr 29 '13 at 9:30
add comment

finally this solve my problem

i enhanced "Andrew" script to make full functional.

ExecuteOrDelayUntilScriptLoaded(OverrideMenuHtc_show, "core.js");

var _MenuHtc_show;

function OverrideMenuHtc_show() {

    _MenuHtc_show = window.MenuHtc_show;
    window.MenuHtc_show = function (m, r, fr, ft, yoff) {
        _MenuHtc_show(m, r, fr, ft, yoff);

        var ctxCur = listcontext;
    //list or library GUID
        var listid = ctxCur.listName;

    if(listid =='your list\library GUID')
    {

                var elm = $(".ms-MenuUIULItem[text='Alert Me']");
                elm.remove();

    }

    };
}
share|improve this answer
add comment

Your Answer

 
discard

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.