Foros‎ > ‎Sharepoint‎ > ‎

Update Logo and CSS using javascript (depending of user domain)

publicado a la‎(s)‎ 10 feb. 2015 6:37 por Ignacio Gonzalez   [ actualizado el 10 mar. 2015 12:13 ]
<script type="text/javascript">

SP.SOD.registerSod('sp.js', '\u002f_layouts\u002fsp.js');
SP.SOD.executeFunc('sp.js', false, function(){});

ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
var currentUser;
function init(){
    this.clientContext = new SP.ClientContext.get_current();
    this.oWeb = clientContext.get_web();
    currentUser = this.oWeb.get_currentUser();
    this.clientContext.load(currentUser);
    this.clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));    
}

function onQuerySucceeded() {
     var userStr = currentUser.get_loginName();
   if (userStr.indexOf("uamceagle.onmicrosoft.com") >= 0)
   {
    editLogo("/logo.jpg", "ctl00_onetidHeadbnnr2");
    editColorsCSS("/NewColors1.css", "Colors");
   
   }
}

function editLogo(logoStr, logoID)
{   

    var edit_save = document.getElementById(logoID);

       edit_save.src = logoStr;                              
}

function editColorsCSS(refStr, cssName)
{   
   var cssReferences = document.getElementsByTagName("link");
    for(i = 0;i < cssReferences.length; i++)
{
   if (cssReferences[i].href.indexOf(cssName) >= 0)
  {
  cssReferences[i].setAttribute('href', refStr);
  break;
  }
}                         
}



</script>

Comments