Click here to Skip to main content
15,893,564 members
Articles / Productivity Apps and Services / Sharepoint

How to Verify if the Page is in Edit Mode using JavaScript in SharePoint 2013

Rate me:
Please Sign up or sign in to vote.
4.50/5 (3 votes)
11 Mar 2015CPOL 13.5K   2  
How to verify if the page is in Edit Mode using JavaScript in SharePoint 2013

Introduction

In one of my projects, there was a need to have a specific edit mode functionality to be implemented, so there might be lot of approaches we can have but I found some of the below approaches that we can implement to verify if the page is in edit mode using JavaScript.

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.

C#
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:

HTML
<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.

C#
var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
if (wikiInEditMode == "Edit")
{
   // wiki page is in edit mode
}
else
{
   // wiki page is not in edit mode
}

Custom Code Snippets

Also, you can place some snippet control to master page or page layout if you have customized it and place the following snippets:

XML
<PublishingWebControls:EditModePanel ID="EditModelPanel1" 
runat="server" PageDisplayMode="Edit">
    <h1>You are in EDIT mode</h1>
    <!-- Place you're javascript for execute only in edit mode -->
</PublishingWebControls:EditModePanel>

<PublishingWebControls:EditModePanel ID="EditModelPanel2" 
runat="server" PageDisplayMode="Display">
    <h1>You are in DISPLAY mode</h1>
    <!-- Place you're javascript for execute only in display mode -->
</PublishingWebControls:EditModePanel>

Cheers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
Having 5 years of experience with IT web technologies. I have been working on C# as my back end language and HTML5, CSS3, JavaScript, jQuery as front end development in Microsoft .net environment. I am currently working in Microsoft SharePoint technology, mainly focused on Branding stuffs. Very passionate about creative front end development and eager to learn new things about it. Somewhat I am gaming freak as well, specifically I am Valve Dota 2 fan. Smile | :)

Comments and Discussions

 
-- There are no messages in this forum --