Search This Blog

Monday, February 28, 2011

Change "Add new announcements" Link on Sharepoint 2010

Whenever we use any list or library like Tasks, Announcements etc, The defaut view has a link that shows as "Add new Announcement" or "Add new event" depending upon the type of list we are using. But its quite possible that in the list, you may be saving data related to News or Event.

I have written a custom javascript function that if added to the page changes the text of "Add new <announcement/event/etc>" link to  "Add new <Title of your list name>").

For this I have written a Content Editor Web Part and added it at the top of the page in  which i am showing the lists.

Add a "Content Editor Web Part" on your page and in the Source Editor, copy/Paste the javascript as given below:

<script type="text/javascript" language="javascript">
//first load the method caller on body load
if (typeof(_spBodyOnLoadFunctionNames) != "undefined")
      if (_spBodyOnLoadFunctionNames != null)

function changeTitle()
var replacedUrlString='';
var splittedValues ='';
var ListName ='';
var aList = document.getElementsByTagName('a'); //get all the anchor tags that are in the pageif(aList.length>0)
     for(var i = 0; i < aList.length; i++)
          var objAnc = aList[i];
         //get the "add new" anchor tags
               //get the list title from the anchot tag url and add the text to tag's HTML               replacedUrlString = objAnc.pathname.replace('/'+objAnc.nameProp,'');
               splittedValues = replacedUrlString.split('/')
               ListName = splittedValues[splittedValues.length-1];
               objAnc.innerHTML = 'Add new ' + ListName.toLowerCase();

1 comment:

  1. I am using this javascript and it is semi-working. Instead of changing to "Add new [Title]" it is simply changing the link to "Add new". This is fine for my purposes, but I'm not sure why it's not pulling in the title?