Is there a way to find out if a page is in Edit Mode from JavaScript?
I know in on the server-side can be found using SPContext.Current.FormContext.FormMode but I can't find any means of doing it from JavaScript.
|
Is there a way to find out if a page is in Edit Mode from JavaScript? I know in on the server-side can be found using |
||||
|
|
|
Looks like you're looking for MSOLayout_InDesignMode
This will refer to value of the following html input control, which is rendering on the page when it is in edit mode:
Update: for wiki pages, you will need _wikiPageMode parameter:
|
|||||||||||
|
|
If you're using publishing pages there is a simple solution to execute javascript only in display (or edit) mode. You can use EditModePanel control to render html depending on the display mode (display or edit). Here is an example:
I hope this can help you. |
|||
|
|
|
There is also a global object available called 'PageState'. Among the various members of state information is "ViewModeIsEdit". If the value of this member is "1" then you are in edit mode (e.g. PageState.ViewModeIsEdit === "1"). Note: This variable is initialized after sp.ribbon.js gets loaded and is initialized from the _spBodyOnLoadFunctionNames array on body load. So if you plan on using this and need to query a value as soon as the page loads, you will need to do a check to see if the object exists yet. |
||||
|
|
|
There must be a bug with the Team site template in SharePoint 2010. This template is the only one where the hidden property MSOLayout_InDesignMode does not change to '1' when you switch to Edit/Design mode. It never has a value. Consequently, I have not been able to detect edit mode in a team site. For me, my issue is that I have some Jquery code to leverage Typekit functionality (more graphical fonts using CSS) and when this runs in edit mode, it causes a 'sp.ui.rte.debug.js access denied' error, which in turn prevents any of the ribbon drop downs (e.g. font) from working. |
|||
|
Declare the javascript variable "IsInPageEditMode" on master page at top as below...
Insert the below mention code immediate after the above code...
Now you can use JavaScript variable IsInPageEditMode whenever you want it... I am using this code in my existing various applications. We dont face any problem till date. If you face any problem please let me know.... Thanks.... Hope this will help you.... |
|||
|
|
Returns true or false. I use this in publishing pages. |
|||
|
|
|
How about checking the ID parameter at the query string if there then you are in edit mode |
|||||||||
|
|
I have this question many times and bored while trying to find good solution. Dont understand why microsoft not include method which can easy determine mode of display page: display or edit. It have many advices of check different variables, but it cant uniquely say that page in design on different type of page(webpart page and wiki page) and on postback or not. Is finally tired me and i write this:
I hope this will save someone some time and nerves. |
|||
|
|
|
|||