0

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

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
}
| improve this answer | |

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