0

This question already has an answer here:

I am running some javascript code in on page but I don't want it running when I try and edit the page. How can I stop this from running in edit page and only when the page has been published

marked as duplicate by Arsalan Adam Khatri, Eric Alexander Dec 16 '14 at 16:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Looks like you're looking for MSOLayout_InDesignMode

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 value of the following html input control, which is rendering on the page when it is in edit mode:

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

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
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.