An Overview of PageState

If you are a SharePoint techie, I bet _spPageContextInfo is your best friend! I am not an orator, but rather a SharePoint techie like you who has been extensively using _spPageContextInfo to reduce server round trips considerably in our JSOM customization for SharePoint. Sahil Malik wrote a great post to introduce _spPageContextInfo.

There are a few requirements, especially with publishing pages where we would like to use the properties of the current page and the current web. And most of us might have implemented an asynchronous call followed by clientcontext.load to get these properties for the current page or web. I was pondering over how we can check if the current page is published or not and then I stumbled upon PageState - another global variable. I thought to post the properties of this object just in case it might be useful for someone.



As you can see, most of the properties are self explanatory, so I will not be describing them here. But there is something about these properties that I must mention. The properties that are not set for the current page, are absent (as we must have expected that they are set to '0' instead of a '1' in the value column). For example, if we check out the page and just save it without checking in, the 'ItemIsMajorVersion' property would simply be missing from this list.

As a second example, you can see that 'ItemIsCheckedOutToCurrentUser' property appears in the list when I checked the page out:



Before you get too exited about this, I must share a word of caution here. PageState belongs to the SP.Ribbon.js library, it would have a value 'undefined' if the ribbon is hidden from the page (one way to hide the ribbon is to select 'Hide Ribbon' option from the Site Actions menu. This option is disabled when the page is checked out, and this means that PageState would definitely be available for a checked out page).

Interesting isn't it? I would encourage you to explore different properties of the PageState variable with F12 and share your observations with all of us.