Tuesday, May 22, 2012

Adding Javascript to a SharePoint Master or Layout page

If you need to add javascript to a SharePoint Master or Layout page, add the script to the Head section or PlaceHolderAdditionalHead content area. Be sure to include the  _spBodyOnLoadFunctionNames.push function so your function is added to the OnLoad method.

<script type="text/javascript">
function UpdateCampusAddress()
{
if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Williams Campus";
}
else if (window.location.href.toLowerCase().startsWith("http://<site name>/"))
{
document.getElementById('CampusAddress').innerHTML = "Sun Lakes Campus";
}
}
_spBodyOnLoadFunctionNames.push("UpdateCampusAddress");
</script>

No comments:

Post a Comment