2

I am working on a SharePoint Server 2013 and I have 4 site collections.

I want to always redirect users to the root site collection if they click on the sites logo from the 4 site collections, so I wrote the following script and added it inside the 4 site collections' master pages:

$(document).ready(function () {
    $("#DeltaSiteLogo a.ms-siteicon-a").prop("href", "/");
    $("DeltaSiteLogo a.ms-siteicon-a").prop("onclick", "");
});

The above workes well in IE (I am using IE11) but in Firefox and Chrome the site logos' url will not reference the root site collection, and will keep referencing each site collection root site.

Can anyone advice on this please?

4

You seem to miss a # on your second line of jQuery, change as below

$(document).ready(function () {
    $("#DeltaSiteLogo a").prop("href", "/");
    $("#DeltaSiteLogo a").prop("onclick", "");
});

or set it in a one-line

$(document).ready(function () {
    $("#DeltaSiteLogo a").prop("href", "/").prop("onclick", "");
});

If that does not work it may be a timing issue, try wrapping it as below:

SP.SOD.executeFunc('sp.js','SP.ClientContext', function(){
    $("#DeltaSiteLogo a").prop("href", "/").prop("onclick", "");
});
  • Doesn't that suitebar load async? (maybe not on SP2013) – Danny '365CSI' Engelman Mar 3 '17 at 10:08
  • @Robert ok will try these approaches.. but why my original code is working well only on IE ,, while these are supose to work well on all browsers venders ?? i mean is there a reason ? – john Gu Mar 3 '17 at 10:11
  • @Danny'365CSI'Engelman the logo is not in the suitebar, it is in the title area. But it is in a DeltaPlaceHolder, so there will possibly be an MDS problem – Robert Lindgren Mar 3 '17 at 10:14
  • @johnG, browsers behave differently, IE is slow as ***, different browsers trigger the DOMContentLoaded event (that jQuery(document).ready listens for at different times – Robert Lindgren Mar 3 '17 at 10:15
  • tested it (in Chrome)... DeltaSiteLogo A is there when the DOMContentLoaded event fires, its the other stuff in the suitebar that comes in async.. sidenote.. the .ms-siteicon-a part in the selector is not required... there only is one A tag inside DeltaSiteLogo – Danny '365CSI' Engelman Mar 3 '17 at 10:18
1

This might not be the best approach but why dont you try building the root site collection url

$(document).ready(function () {
   var rootSite=window.location.protocol+"//"+window.location.host
   $("#DeltaSiteLogo a").attr("href", rootSite)        
});
  • your appraoch looks promising .. but i am note sure if "rootSite=window.location.protocol+"//"+window.location.host" is suppose to work as is !! and should it be inside the $(document).ready ?? – john Gu Mar 3 '17 at 11:23
  • now your script will work on firefox + IE but not inside chrome..now i did my test by hard-coding the server root url as follow $("#DeltaSiteLogo a").attr("href", "http://servername/").. – john Gu Mar 3 '17 at 11:42
  • even when you hard code your url chrome doesn't take you to the root site? – rjv91 Mar 3 '17 at 12:02
  • unfortunately the answer is yes... – john Gu Mar 3 '17 at 15:45
0

Try it as below:

$(document).ready(function () {
    $("#DeltaSiteLogo a").attr("href", "/")        
});
  • ,, ok will try this .. but why this should work while my original code did not ? as both have valid logic ,, is this correct? – john Gu Mar 3 '17 at 10:12
  • your script did not solve the problem on firefox & chrome – john Gu Mar 3 '17 at 11:15
  • Thats strange , what version of jquery are you using ? I suggest adding this code at the bottom of the master page just before </body> tag. Its working fine at my end using jquery-1.12.4.min.js – Gautam Sheth Mar 3 '17 at 11:19
  • i am using jquery 1.11.3.. and i am placing the scripts after the <SharePoint:CustomJSUrl runat="server" /> inside my master pages as follow:- <SharePoint:CustomJSUrl runat="server" /> <script type="text/javascript" src="/resources/jquery-1.11.3.js" ></script> <script type="text/javascript" src="/resources/changeLogoURL.js" ></script> ?? – john Gu Mar 3 '17 at 11:32
  • ok can you move the <script type="text/javascript" src="/resources/changeLogoURL.js" ></script> to the bottom of the master page just above the </body> and check ? jquery version is fine – Gautam Sheth Mar 3 '17 at 11:34

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.