As per client request, we created webzones which creates 'collapsible regions' of the content. So if you add multiple webparts to a 'collapsible region' zone, the webparts collapse and clicking on the header will expand them (using a expanded css class), collapsing any other open part. So at any time, only 1 webpart is expanded at a time.

Now we can across an issue in IE that, when in edit mode, clicking on the header wont expand or reveal the content. Well, it does, but only if you click it in a very unintuitive way (you kinda get lucky to get it to expand).

The solution that has been proposed was to, on Edit, expand all the regions for easy editing.

But I am unsure on how to catch or be aware that the page has gone into Edit mode in order for me to use some JavaScript to then expand all collapsed parts.

Is there a way to handle this or achieve this?



This is what we are using currently in one of our projects to check if a page is in edit mode or not:

// An accesser indicating whether or not the current page is in design mode.
 function inDesignMode () {
    var result = (window.MSOWebPartPageFormName != undefined) && ((document.forms[window.MSOWebPartPageFormName] && document.forms[window.MSOWebPartPageFormName].MSOLayout_InDesignMode && ("1" == document.forms[window.MSOWebPartPageFormName].MSOLayout_InDesignMode.value)) || (document.forms[window.MSOWebPartPageFormName] && document.forms[window.MSOWebPartPageFormName]._wikiPageMode && ("Edit" == document.forms[window.MSOWebPartPageFormName]._wikiPageMode.value)));
    return result || false;
| improve this answer | |

Try the following:

if (document.forms["aspnetForm"]["MSOLayout_InDesignMode"].value == 1) {
   //do your stuff

If you want to be sure-sure, you can double check with this property:


which should have a value of "Design" if a page is in edit mode, or "Browse" if it's in display mode.

As well you can check in what state the Ribbon is with the following line of code:


If the page is in Display mode, you should get an empty string value (""), if it's in Edit mode, it should be "1". This was tested and is working fine for me.

| improve this answer | |
  • 1
    If I remember correctly this differs between different page types, so this will not work on all pages (I think for publishing pages it is another property you need to check or vice versa) – Robert Lindgren Jul 14 '15 at 9:59
  • You might be right. I'll double check and update the answer. – Paul Strupeikis Jul 14 '15 at 10:07
  • 1
    Maybe you confused the property with document.forms["aspnetForm"]["MSOAuthoringConsole_FormContext"].value as this one doesn't show a value of 1 if a wiki page is in edit mode. I tested the MSOLayout_InDesignMode and it seems to be working for publishing, wiki and web part pages. – Paul Strupeikis Jul 14 '15 at 10:25
  • Yeah that could be it :) – Robert Lindgren Jul 14 '15 at 10:26
  • Thanks Paul! Good answer! I originally implemented your solution and worked well. I ended up using Nadeem's solution as it seems to cover more ground, but thanks for your eagerness to assist and for explaining various things around it. :) – Simon Jul 14 '15 at 12:23

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