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" />
var inDesignMode = document.forms[MSOWebPartPageFormName].MSOLayout_InDesignMode.value;
if (inDesignMode == "1")
{
// page is in edit mode
}
else
{
// page is in browse mode
}
var wikiInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value;
if (wikiInEditMode == "Edit")
{
// Page is in edit mode
}
else
{
// Page is not in edit mode
}