MattsBits
MattsBits

MattsBits

Test If Sharepoint Page Is In Edit Mode Using Javascript  

by Matt Hawkins, 26/04/2012
Categories : Sharepoint

When adding JavaScript to Sharepoint pages it is useful to know if the page is in edit more. This allows your script to react appropriately.

The code below tests if the page is in edit mode.

In order to determine if the page is in edit mode we test for the existance of a particular form element. This element is only included on the page when it is in edit mode. The element is :


<input type="hidden" name="MSOLayout_InDesignMode" id="MSOLayout_InDesignMode" value="1" />


The JavaScript test is :


var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

if (inDesignMode == "1")
{
// page is in edit mode
}
else
{
// page is in browse mode
}


You need to use a different test for Wiki pages:


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

Author : Matt Hawkins  Last Edit By : Matt Hawkins
PHP Powered  MySQL Powered  Valid XHTML 1.0  Valid CSS  Firefox - Take Back The Web  EUKHost - Recommended Webhosting Solutions

MattHawkins CMS v3.0 - Copyright 2009-2022