SharePoint

How to remove the “Personalize this Page” link in the Welcome menu using JQuery

We are currently developing a search portal in SharePoint 2010 that will be very similar to Google’s “iGoogle” concept —  on the homepage we have a simple search box with personalizable web part zones underneath so that users can personalize the page to their liking.  We also have several other pages and sub sites off of our main portal site of which we do not wish to allow personalization.  So in short, we want to allow personalization only on the home page of the portal, but nowhere else in that particular site collection.

There may be other ways to accomplish this, but I found that JQuery offered a very simple solution.  Basically you check the “window.location.pathname” object to see if it’s not equal to the relative path of the home page.  Then get a handle on the “Personalize this Page” control and hide it by using the JQuery “remove()” function   Here is the code snippet:

<script type=”text/javascript”src=”https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js”></script>

<script type=”text/javascript”>   
    $(document).ready(function () {
if (window.location.pathname != “/Pages/default.aspx”) {
$(“#[id*=ID_Personalize]”).remove();
}
});

 </script> 

I want to explain what the highlighted section above is doing.  In order to find the proper control, we are looking for a menu item that contains “ID_Personalize” in the ID attribute.  The reason we are doing a JQuery Contains search is because the ID is dynamically generated by SharePoint and could be different based on different permission levels.  For example, when I viewed the source of my portal home page, I discovered that the control’s ID was “zz24_ID_PersonalizePage”:

<ie:menuitem id=”zz24_ID_PersonalizePage” type=”option” iconSrc=”/_layouts/images/menupersonalize.gif” onMenuClick=”javascript:ChangeLayoutMode(true);” text=”Personalize this Page” description=”Add, remove, or update Web Parts on this page.” menuGroupId=”300″></ie:menuitem>

I have full control of this site collection.  When I logged in as a user with contribute or read permission, the ID of the control was “zz18_ID_PersonalizePage”, and when logged in as a user with design permission, it was “zz22_ID_PersonalizePage”.  The reason it does this is because for each possible control in the menu, it uses a sequential number as part of the ID.  If you have fewer permissions, that number will be smaller because there are fewer conrols that you are allowed to see.  For this reason you must search for the partial ID name.

You could also use this approach to selectively hide any other link on the Welcome menu if you had reason to.  Just view the source to obtain the constant portion of the menu control’s ID.

I just want to disclaim that I am in no way a JQuery expert, so if you see anything wrong with this approach, please let me know!  It does seems to be working fine for our needs.

(Visited 674 time, 1 visit today)

About Me

Wendy Neal

Wendy Neal

I am a .NET SharePoint Developer for DMI. I've worked with SharePoint since 2007. I love to share my passion for SharePoint and Office 365 by speaking at various industry and user group events, as well as writing articles for various publications and this blog.   Read More

TwitterCounter for @SharePointWendy
MCSA Office 365
Top 50 SharePoint Blogs

Buy My Book

Archives

  • 2017 (1)
  • 2016 (8)
  • 2015 (23)
  • 2014 (20)
  • 2013 (22)
  • 2012 (15)
  • 2011 (13)