Thursday, June 9, 2016

How do I know if the page is in Edit Mode from JavaScript?


Server Side Code: SPContext.Current.FormContext.FormMode var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value; if (inDesignMode == "1") { // page is in edit mode } else { // page is in browse mode } <input type="hidden" name="MSOLayout_InDesignMode" id="MSOLayout_InDesignMode" value="1" /> Update: for wiki pages, you will need _wikiPageMode parameter: var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value; if (wikiInEditMode == "Edit") { // wiki page is in edit mode } else { // wiki page is not in edit mode } CSOM or ECMA Script: SP.Ribbon.PageState.Handlers.isInEditMode() Returns true or false. I use this in publishing pages.

No comments:

Post a Comment