0

How can I remove certain entries of the context menu (marked in my screenshot with red border) by using Script Editor Web Part? As an example, I would like to remove the entries "Im Browser bearbeiten" and "Konformitätsdetails".

enter image description here

Thank you very much in advance.

1

What you could do, is to override the function in Core.js on the current page instead. If its a library the actions are added in the AddDocLibMenuItems. And the View/Edit Properties are added from the AddShareNamespaceMenuItems function. So you could add this function to your page, just make sure its loaded after Core.js:

function AddDocLibMenuItems(m, ctxt) {
    if (typeof window.Custom_AddDocLibMenuItems != "undefined") {
        if (window.Custom_AddDocLibMenuItems(m, ctxt))
            return;
    }
    var RootFolder = GetRootFolder(ctxt);
    var menuOption;
    var strDisplayText;
    var strAction;
    var strImagePath;

    //AddSharedNamespaceMenuItems(m, ctxt);
    var currentItemEscapedFileUrl;

    if (currentItemFileUrl != null)
        currentItemEscapedFileUrl = escapeProperly(unescapeProperly(currentItemFileUrl));
    var serverFileRedirect = itemTable.getAttribute("SRed");
    var systemCheckout = currentItemCheckedOutUserId == String(SYSTEM_ACCOUNT_ID) && ctxt.CurrentUserId != String(SYSTEM_ACCOUNT_ID);

    if (HasRights(0x0, 0x4) && HasRights(0x10, 0x0) && !systemCheckout && (serverFileRedirect == null || serverFileRedirect == "" || HasRights(0x0, 0x20))) {
        if (ctxt.isWebEditorPreview == 0 && ctxt.listBaseType == 1) {
            if (ctxt.listTemplate != 119) {
                setDocType();
                if (currentItemAppName != "" && currentItemOpenControl != "") {
                    if (!(ctxt.IsAppWeb && currentItemProgId == SPDesignerProgID)) {
                        strDisplayText = "";
                        if (currentItemAppName != " ")
                            strDisplayText = StBuildParam(Strings.STS.L_EditIn_Text, currentItemAppName);
                        else {
                            var objEditor = StsOpenEnsureEx2(currentItemOpenControl + ".3");

                            if (objEditor != null)
                                strDisplayText = Strings.STS.L_EditInApplication_Text;
                        }
                        if (strDisplayText != "") {
                            strAction = "editDocumentWithProgID2('" + currentItemFileUrl + "', '" + currentItemProgId + "', '" + currentItemOpenControl + "', '" + String(bIsCheckout) + "', '" + ctxt.HttpRoot + "', '" + currentItemCheckedoutToLocal + "', '" + currentItemOpenApp + "')";
                            strImagePath = ctxt.imagesPath + currentItemIcon;
                            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(260));
                            menuOption.id = "ID_EditIn_" + currentItemAppName;
                            menuOption.style.cssText = "display:none";
                            CUIInfo(menuOption, "EditDocument", ["EditDocument"]);
                        }
                    }
                }
            }
        }
    }
    CAMSep(m);
    if (HasRights(0x0, 0x4)) {
        if (currentItemFSObjType != "1") {
            if (ctxt.listBaseType == 1) {
                AddCheckinCheckoutMenuItem(m, ctxt, currentItemEscapedFileUrl);
            }
        }
    }
    if ((ctxt.verEnabled == 1 || ctxt.isModerated) && currentItemFSObjType != "1") {
        AddVersionsMenuItem(m, ctxt, currentItemEscapedFileUrl);
    }
    if (HasRights(0x0, 0x4)) {
        if (ctxt.isModerated == true && HasRights(0x0, 0x10) && ((currentItemModerationStatus == String(2) || !ctxt.EnableMinorVersions) && currentItemCheckedOutUserId == "" || currentItemFSObjType == "1")) {
            strDisplayText = Strings.STS.L_ModerateItem_Text;
            strAction = "NavigateToApproveRejectAspx(event, '" + ctxt.HttpRoot + "/_layouts/15/approve.aspx?List=" + ctxt.listName + "&ID=" + currentItemID;
            strAction = AddSourceToUrl(strAction) + GetRootFolder(ctxt) + "')";
            strImagePath = ctxt.imagesPath + "apprj.gif";
            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(850));
            CUIInfo(menuOption, "Moderate", ["Moderate"]);
            menuOption.id = "ID_ModerateItem";
        }
    }
    CAMSep(m);
    AddWorkflowsMenuItem(m, ctxt);
    if (currentItemFSObjType != "1") {
        if (ctxt.PortalUrl != null) {
            strDisplayText = Strings.STS.L_AddToMyLinks_Text;
            strAction = "Portal_Tasks('PinToMyPage')";
            ;
            strImagePath = "";
            menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1000));
            CUIInfo(menuOption, "AddToMyLinks", ["AddToMyLinks"]);
            menuOption.id = "ID_AddToMyLinks";
            menuOption.style.display = "none";
        }
    }
    else if (ctxt.listBaseType == 1 && HasRights(0x10, 0x0)) {
        AddWorkOfflineMenuItem(m, ctxt, currentItemFileUrl);
    }
    if (HasRights(0x80, 0x0) && typeof _spPageContextInfo != 'undefined' && _spPageContextInfo != null && typeof _spPageContextInfo.alertsEnabled == 'boolean' && _spPageContextInfo.alertsEnabled) {
        strDisplayText = Strings.STS.L_Subscribe_Text;
        strAction = "NavigateToSubNewAspxV4(event, '" + ctxt.HttpRoot + "', 'List=" + ctxt.listName + "&ID=" + currentItemID + "')";
        strImagePath = "";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1100));
        CUIInfo(menuOption, "Subscribe", ["Subscribe"]);
        menuOption.id = "ID_Subscribe";
        menuOption.style.display = "none";
    }
    if (currentItemFSObjType != "1") {
        AddSendSubMenu(m, ctxt);
        AddGotoSourceItemMenuItem(m, ctxt, itemTable, currentItemFSObjType);
        AddDocTransformSubMenu(m, ctxt);
    }
    CAMSep(m);
    AddManagePermsMenuItem(m, ctxt, ctxt.listName, currentItemID);
    if (HasRights(0x0, 0x8) && !systemCheckout) {
        strDisplayText = Strings.STS.L_DeleteDocItem_Text;
        var isCopy = "false";

        if (typeof itemTable.getAttribute("CSrc") != "undefined" && itemTable.getAttribute("CSrc") != null && itemTable.getAttribute("CSrc") != "") {
            isCopy = "true";
        }
        strAction = "DeleteDocLibItem('" + ctxt.HttpPath + "&Cmd=Delete&List=" + ctxt.listName + "&ID=" + currentItemID + "&owsfileref=" + currentItemEscapedFileUrl + "&NextUsing=" + GetSource() + "'," + isCopy + ")";
        strImagePath = ctxt.imagesPath + "delitem.gif";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1190));
        menuOption.id = "ID_DeleteDocItem";
        CUIInfo(menuOption, "Delete", ["Delete"]);
    }
    if (HasRights(0x0, 0x4) && currentItemFSObjType == "1" && ctxt.ContentTypesEnabled && ctxt.listTemplate != 108) {
        strDisplayText = Strings.STS.L_CustomizeNewButton_Text;
        strAction = "STSNavigate('" + ctxt.HttpRoot + "/_layouts/15/ChangeContentTypeOrder.aspx?List=" + ctxt.listName + "&RootFolder=" + currentItemEscapedFileUrl;
        strAction = AddSourceToUrl(strAction) + "')";
        strImagePath = "";
        menuOption = CAMOpt(m, strDisplayText, strAction, strImagePath, null, String(1170));
        CUIInfo(menuOption, "ChangeNewButton", ["ChangeNewButton"]);
        menuOption.id = "ID_CustomizeNewButton";
    }
}

Simply use this

<style> li.ms-core-menu-item[text="TEXT(of the entry which should be hidden)"] { display: none !important; } </style>

Please refer theLink for Source

  • Thank you. Your link for source brought me to the page, where I found a code for CSS which works. I just embed following CSS to Script Editor Web Part: <style> li.ms-core-menu-item[text="TEXT(of the entry which should be hidden)"] { display: none !important; } </style> – SteffPoint May 20 '16 at 12:53
  • You are welcome. Happy Coding!!! – Mohamed Arif May 20 '16 at 13:12
1

The easiest way to do it, is to add this CSS to a Script Editor:

<style> li.ms-core-menu-item[text="TEXT(of the entry which should be hidden)"] { display: none !important; } </style>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.