一、 说明
在SharePoint页面中存在连接与导出功能按钮,如下图所示,由于权限管理限制不足以满足连接与导出功能按键显示与隐藏,需要通过脚本的形式添加页面的webpart中,让页面刷新时自动隐藏功能按钮。
二、 操作
编辑页面
添加web部件-内容编辑器
光标停留内容编辑器编辑框,在页面左上角点击设置文字格式,编辑源
编辑源框黏贴脚本代码,点击确定
脚本如下
<script><span id="ms-rterangecursor-start"></span><span id="ms-rterangecursor-end"></span>
(function(){
if (typeof(_spBodyOnLoadFunctions) === 'undefined' || _spBodyOnLoadFunctions === null) {
return;
}
_spBodyOnLoadFunctions.push(function() {
if (typeof(SPClientTemplates) === 'undefined' || SPClientTemplates === null || (typeof(APD_InAssetPicker) === 'function' && APD_InAssetPicker())) {
return;
}
var registerOverrideToHideSocialActions = function(id) {
var socialactionsOverridePostRenderCtx = {};
socialactionsOverridePostRenderCtx.BaseViewID = 'Callout';
socialactionsOverridePostRenderCtx.ListTemplateType = id;
socialactionsOverridePostRenderCtx.Templates = {};
socialactionsOverridePostRenderCtx.Templates.Footer = function(renderCtx) {
var renderECB;
if (typeof(isSharedWithMeView) === 'undefined' || isSharedWithMeView === null) {
renderECB = true;
} else {
var viewCtx = getViewCtxFromCalloutCtx(renderCtx);
renderECB = !isSharedWithMeView(viewCtx);
}
// By setting a null value as 2nd parameter, we do not specify additional callout actions.
return CalloutRenderCustomFooterTemplate(renderCtx, null, renderECB);
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(socialactionsOverridePostRenderCtx);
}
// Hide actions for default Document Libraries
registerOverrideToHideSocialActions (101);
// Hide actions for the document library on your My Site
registerOverrideToHideSocialActions (700);
function CalloutRenderCustomFooterTemplate(renderCtx, calloutActionMenuPopulator, renderECB) {
if (typeof calloutActionMenuPopulator === 'undefined' || calloutActionMenuPopulator === null) {
calloutActionMenuPopulator = CalloutOnPostRenderCustomTemplate;
}
if (typeof renderECB === 'undefined' || renderECB === null) {
renderECB = true;
}
var calloutID = GetCalloutElementIDFromRenderCtx(renderCtx);
AddPostRenderCallback(renderCtx, function() {
var calloutActionMenu = new CalloutActionMenu(calloutID + '-actions');
calloutActionMenuPopulator(renderCtx, calloutActionMenu);
calloutActionMenu.render();
});
var ecbMarkup = [];
if (renderECB) {
ecbMarkup.push('<span id=' + StAttrQuote(calloutID + '-ecbMenu') + ' class="js-callout-actions js-callout-ecbActionDownArrow">');
ecbMarkup.push(RenderECBinline(renderCtx, renderCtx.CurrentItem, renderCtx.CurrentFieldSchema));
ecbMarkup.push('</span>');
}
return Callout.GenerateDefaultFooter(calloutID, ecbMarkup.join(''));
}
function CalloutOnPostRenderCustomTemplate(renderCtx, calloutActionMenu) {
var listItem = renderCtx.CurrentItem;
var openText = GetCallOutOpenText(listItem, renderCtx);
calloutActionMenu.addAction(new CalloutAction({
text: openText,
onClickCallback: function(calloutActionClickEvent, calloutAction) {
CalloutAction_Open_OnClick(calloutActionClickEvent, calloutAction, renderCtx);
}
}));
}
});
})();
function renderHeaderTemplateForDocuments(renderCtx, fRenderHeaderColumnNames){
var viewData = eval(renderCtx.ListSchema.ViewSelectorPivotMenuOptions);
ClientPivotControl.prototype.SurfacedPivotCount = 3;
return RenderHeaderTemplate(renderCtx, fRenderHeaderColumnNames); //render default Header template
}
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
Templates: {
Header: renderHeaderTemplateForDocuments
}
});
</script><style>
#Ribbon\.Documents\.Copies-LargeMedium-0{display:none;}
li[text="Download a Copy"] {
display:none;
}
li[id="Ribbon.Library.Actions"] {
display:none;
}
#Ribbon\.Library\.Actions\.OpenWithExplorer-Medium{display:none;}
#WPQ2_ListTitleViewSelectorMenu_Container_overflow{display:none;}
#Ribbon\.Library\.CustomViews{display:none;}
</style>
停止编辑
查看效果,发现连接和导出功能按钮隐藏不再显示了。
以上为个人整理总结的知识,如有遗漏或错误欢迎留言指出、点评,如要引用,请写联系通知,未经允许谢绝转载。