0

One of the Projects I am working on, I have to display SharePoint site name on a SharePoint library default edit form, I am using below code from tech net but it does not work, can someone please help me out to correct this and make it to work.

<script language="javascript" type="text/javascript">
_spBodyOnLoadFunctionNames.push("GetSiteName");

function GetSiteName(){
  var SiteName = document.getElementById('ctl00_PlaceHolderSiteName_onetidProjectPropertyTitle').innerHTML;//get the ID from 'view source' page
document.getElementById('lblsitename').innerHTML = SiteName;
}
</script>
<html>
<label id="lblsitename"></label>
</html></div>

I am dynamically trying to display the site name on a share point library upload (default edit form) so users get to see what site they are working on and this has to be dynamic in nature which is why I am using JSOM approach.

FYI, I am working with SharePoint online. Thanks in advance.

2

You can use _spPageContextInfo.webTitle to get current site title.

document.getElementById('lblsitename').innerHTML = _spPageContextInfo.webTitle;

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.