I have the URL of a web (http://intranet/sites/site/web) and I would like to get it's title. I know in PowerShell or C# you could create a Web object from the URL and get the title. Can you do something similar with JavaScript and if so how?


Yes, you can use (SP.js) to Get Web Site Properties like

  • Title (Web.get_title();).
  • Description (Web.get_description();).
  • Language (Web.get_language();).
  • UI Version (Web.get_uiVersion();).
  • Created (Web.get_created();).

To get Page Title, Just add the below code in Script Editor Web Part to your page


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready(function () {
    // Wait until SP.JS has loaded before calling getWebUserData 
    ExecuteOrDelayUntilScriptLoaded(retrieveWebSite, "sp.js");

function retrieveWebSite() {
   var clientContext = new SP.ClientContext("http://epm/workflow");
   this.oWebsite = clientContext.get_web();
      Function.createDelegate(this, this.onQuerySucceeded), 
      Function.createDelegate(this, this.onQueryFailed)

function onQuerySucceeded(sender, args) {
   alert('Title: ' + this.oWebsite.get_title() + 
      ' Description: ' + this.oWebsite.get_description());

function onQueryFailed(sender, args) {
  alert('Request failed. ' + args.get_message() + 
      '\n' + args.get_stackTrace());

Just replace this line

var clientContext = new SP.ClientContext("http://epm/workflow");

with your site URL

clientContext = new SP.ClientContext("http://intranet/sites/site/web");

Note: you can get the current site URL as the following:

var clientContext = new SP.ClientContext(_spPageContextInfo.siteServerRelativeUrl);

Check also Ref: Get Web Site Properties

| improve this answer | |

You can use REST API to get web Title. Assuming your web is at url http://intranet/sites/site/myweb put below link in browser you get be able to see json object.


Json Response.

    ......//all other properties.
   "Title": "test",
        "TreeViewEnabled": false,
        "UIVersion": 15,
        "UIVersionConfigurationEnabled": false,
        "Url": "https://fcatcs.sharepoint.com/sites/dev/test",
        "WebTemplate": "STS"
| improve this answer | |

SP 2016 OnPrem:

var siteTitle = _spPageContextInfo.webTitle;  // returns name of site
| improve this answer | |

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.