Introduction
While creating the app in SharePoint we are using JavaScript and Client side object model. In development of app, we would require some basic properties to handle our app, SharePoint provide the few properties with _spPageContextInfo object.
_ spPageContextInfo will provide the below properties
- webServerRelativeUrl
- webAbsoluteUrl
- siteAbsoluteUrl
- serverRequestPath
- layoutsUrl
- webTitle
- webTemplate
- tenantAppVersion
- isAppWeb
- webLogoUrl
- webLanguage
- currentLanguage
- currentUICultureName
- currentCultureName
- env
- nid
- fid
- clientServerTimeDelta
- updateFormDigestPageLoaded
- siteClientTag
- crossDomainPhotosEnabled
- webUIVersion
- webPermMasks
- pagePersonalizationScope
- userId
- userLoginName
- systemUserKey
- alertsEnabled
- siteServerRelativeUrl
- allowSilverlightPrompt
- themedCssFolderUrl
- themedImageFileNames
Implementation
You can also access this object in JavaScript model as
<script type=”text/javascript”>
var propertyValue = _spPageContextInfo.PropertyName
</script>
Example
Get current login user name
<script type=”text/javascript”>
var loginName = _ spPageContextInfo. userLoginName
alert(loginName)
</script>
The above example will show an alert of value current user login.
To check the properties and its value of _spPageContextInfo, browse a SharePoint web page and open its view source (HTML – right click on web page à view page source) and find text “spPageContextInfo”.
See below screen shot
Posted by Vivek Jagga
Please follow and like us:
Technical Solutions Professional | Modern Workplace Architect Lead | Microsoft 365 | SharePoint | Power Platform | MS Teams | React
Leave a Reply