Skip to content

Instantly share code, notes, and snippets.

@dhunmoon
Created May 5, 2016 08:53
Show Gist options
  • Save dhunmoon/881ab063f5f4a44f49d6e2ad21d062f4 to your computer and use it in GitHub Desktop.
Save dhunmoon/881ab063f5f4a44f49d6e2ad21d062f4 to your computer and use it in GitHub Desktop.
How to Verify if the Page is in Edit Mode using JavaScript in SharePoint 2013
//For Publishing Page
//SharePoint default input called MSOLayout_InDesignMode is there. If the value is 1, then page is in edit mode else it is in display mode.
//Hide Copy Code
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode == "1"){
// page is in edit mode
}
else{
// page is in browse mode
}
//This will refer to the value of the following HTML input control, which is rendering on the page when it is in edit mode:
//----------------------------------------------------------//
/*<input id="MSOLayout_InDesignMode" name="MSOLayout_InDesignMode"
type="hidden" value="1" />*/
/************************************************************************/
//For Wiki Pages
//Same as above another default input _wikiPageMode parameter will be used. If the value is Edit page is in edit mode else in display mode.
var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
if (wikiInEditMode == "Edit"){
// wiki page is in edit mode
}
else{
// wiki page is not in edit mode
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment