SharePoint page state is commonly used to perform specific actions based on the state. For instance, isInEditMode is used to determines whether the page is currently being edited. For more page state methods and their description please visit next MSDN link:
var inEditmode = SP.Ribbon.PageState.Handlers.isInEditMode();
In this blog post I will explain why this solution sometimes is not working and present the solution.