4

I am working on a web application which contain 2 site collections , with the following URLs:-

  • http//servername

  • http://servername/HR

and the second site collection have two subsites , with the following url:-

  • http://servername/HR/Staff

  • http://servername/HR/manager

now all of the above 4 sites (2 site collections + 2 subsites) have a site logo. now the default behavior is that clicking on the logo will redirect to the home page of the current site, either a site collection or sub site.

so i need to force the logo image to allow redirect to the root site collection , so i wrote the following script :-

$(document).ready(function () {


    $("a.ms-siteicon-a").attr("href", "/");
    $("a.ms-siteicon-a").attr("onclick", "");
});

and i reference it inside all the sites master pages. but i got this behavior;-

  1. on IE the above script will work on the site collection. so if i am inside the HR site collection and i click on the logo i will redirect to the root http://servername/ instead of http://servername/HR/ which is correct. while on firefox the logo for the HR will keep redirecting to http://servername/HR

  2. on both IE & Firefox, if i am inside a sub site such as http://servername/HR/staff the logo will keep redirecting to the subsite home page instead of the root as mentioned on the script.

so can anyone adivce how to force the logo on all the sites to always redirect to the root ?

Thanks

  • 1
    In SharePoint terminology http:// servername/HR is not a site collection but a subsite (even if it contains subsites). On the same web application you will have a site collection like this "http:// servername". Other site collections will have a url like this "http:// servername/sites/anothersitecol1" or "http:// servername/sites/anothersitecol2". It doesn't answer the question but it is good to know ;) – Sylvain Gantois Sep 17 '15 at 8:13
  • are you sure that your script updates the html of the Logo-Link? – Leopold Lerch Sep 17 '15 at 9:25
  • @Sylvain not sure if this is correct now if i create a site collection under /HR/ where HR is an Explicit inclusion managed path , then why u consider servername/hr/ as a subsite.. i did not get your point ! – john Gu Sep 17 '15 at 11:12
  • Well in that case you are right, sorry I thought it was a beginner terminology mistake ;) – Sylvain Gantois Sep 20 '15 at 9:37
1

Instead of JavaScript we can make respective changes in master page. Assuming you are on SharePoint 2013 on-premise. If you notice in the seattle.master file, you can find a div with ID siteIcon which is responsible for redirection. Refer below.

<div id="siteIcon" class="ms-tableCell ms-verticalAlignTop">
    <SharePoint:AjaxDelta id="DeltaSiteLogo" BlockElement="true" runat="server">
        <SharePoint:SPSimpleSiteLink CssClass="ms-siteicon-a" runat="server" id="onetidProjectPropertyTitleGraphic" >
            <SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/_layouts/15/images/siteIcon.png?rev=23" runat="server"/>
        </SharePoint:SPSimpleSiteLink>
    </SharePoint:AjaxDelta>
</div>

Now to customize the redirection, firstly I have my own custom master page, where I have replaced the above AjaxDelta control to SPLinkButton which allows me to specify the Navigate Url.

NavigateUrl="~sitecollection/"

The above attribute value will redirect to root. Refer below full div structure.

<div id="siteIcon" class="ms-tableCell ms-verticalAlignTop">
    <SharePoint:SPLinkButton runat="server" NavigateUrl="~sitecollection/" id="onetidProjectPropertyTitleGraphic">
        <SharePoint:SiteLogoImage name="onetidHeadbnnr0" id="onetidHeadbnnr2" LogoImageUrl="/Style%20Library/Images/Logo.png" ToolTip="Home" AlternateText="Logo" runat="server"/>
    </SharePoint:SPLinkButton>
</div>
  • your solution will Redirect to the RootWeb of the current Sitecollection. That is not what he want. He seems to want to always Redirect to the RootWeb of the Sitecollection in the Webapplications Root – Leopold Lerch Sep 17 '15 at 9:29
  • @LeopoldLerch yes exactly i want to always redirect to the root url which is "servername" – john Gu Sep 17 '15 at 11:05
  • @Asad now i tried adding the SPlinkButton as you mentioned but i got the following error :- "The ID 'DeltaSiteLogo' is already used by another control. " – john Gu Sep 17 '15 at 12:45
  • 1
    @johnG Did you use the last snippet in answer? You should be using that, and this do not contain DeltaSiteLogo as we are replacing it. – Asad Refai Sep 17 '15 at 13:05
  • 1
    @johnG Did that solve your problem? – Asad Refai Sep 17 '15 at 13:47
0

Assuming that your RootSite is located at the Servers Root, you could simply Change your masterpage where your SiteLogoImage is situated to:

<a class="ms-siteicon-a" href="/">
      <SharePoint:SiteLogoImage CssClass="ms-siteicon-img" name="onetidHeadbnnr0" ID="onetidHeadbnnr2" LogoImageUrl="images/Logo_t.png" runat="server" />
</a>

So you won´t Need the JavaScript anymore

  • 1
    but i was searching for a way to apply this change inside a javascript and reference this javascript from all the master pages, this will be a cleaner solution. as my current javascript contain many customizations, and i do not need to apply the customization on each master page , i just reference the javascript on all the master pages, and have a centralized control for all the changes. of course if the change can not be achieved using javascript then the last choice will be to modify the master page itself.. thanks. – john Gu Sep 17 '15 at 11:14
  • sry, I don´t get your Point. You create custom masterpages for all the sites, and then attach a Javascript which again changes the already customized pages again on Client side?. that doesn´t Sound centralized to me at all. – Leopold Lerch Sep 17 '15 at 11:19
  • 1
    however, then you will have to debug the JavaScript. Maybe it is executed too soon. the document.ready function does not work well in relation to SharePoint, as SharePoint does many Renderings clientside (which also happens AFTER document is loaded). you should consider the SharePoint built in equivalents like "_spBodyOnLoadFunctionNames". – Leopold Lerch Sep 17 '15 at 11:22
  • somehow it is centralized, now let say i want to change the redirect URL to a specific page in the future, then i can do so from the javascript itself and have the effect on all the master pages which reference the javascript. but if i am changing the master pages themselves then i will end up modifying all the master pages to chnage the redirect URL, also if i want to return back to the defualt behavior where each logo redirect to the current site (SC or subsite) , then i can comment the related code on the script file instead of modifying all the master pages,, did u get my point ? – john Gu Sep 17 '15 at 11:24

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.