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">

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

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.

1 Answer 1


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 and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.