Thursday, January 21, 2010

Renaming the menu items in SharePoint Site Libraries and Lists for a Specific Site

In SharePoint document Library/List we find menu items like New, Uploads, Actions and Settings etc. At times there might be requirements to rename these menu items for a specific site. The following Javascript function can be used to achieve the objective.




The code snippet shown below can be called from inside the specific SharePoint Page.

e.g AllItems.aspx page inside a Document Library/List.

This javascript function needs to be called on Page load event using _spBodyOnLoadFunctionNames.push method.

<script language="javascript" type="text/javascript">

_spBodyOnLoadFunctionNames.push("renameMenuItem('New', 'My New')");
_spBodyOnLoadFunctionNames.push("renameMenuItem('Settings', 'My Settings')");

function renameMenuItem(oldMenuItemName, newMenuItemName)
{

var vAnchorTag;

var vAllAnchorTags = document.getElementsByTagName('a');
if(oldMenuItemName.length!=0)

{
for (var j = 0; j < vAllAnchorTags.length; j++)

{

vAnchorTag = vAllAnchorTags[j];


if (vAnchorTag.innerText.indexOf(oldMenuItemName)!=-1)

{
vAnchorTag.innerText = newMenuItemName;
try

{

if(newMenuItemName.length != 0)

{

vAnchorTag.parentNode.previousSibling.firstChild.firstChild.alt

= newMenuItemName;


}

else
{

vAnchorTag.parentNode.previousSibling.firstChild.firstChild.alt

= oldMenuItemName;

}

}
catch(err)
{
}
}
} // End For
} // End If
}// End Function
</script>

Check it out from here: http://www.mindfiresolutions.com/Renaming-the-menu-items-in-SharePoint-Site-Libraries-and-Lists-for-a-Specific-Site-209.php
Try it out and enjoy...

No comments:

Post a Comment