I have some javascript in a CEWP that I want to execute only when the page is in display mode. I've used firebug to scour the page for some "msEditMode" type of variable or something I can rely on.

I've seen tons of questions and answers about how to tell if a page is in edit mode, from server side, but I cannot find a solution for how to tell if the page is in edit mode, client side.

Can anyone point me in the right direction? Do I need to create a web part that simply emits such a variable? (That seems like overkill to me.)

Thanks so much!

4 Answers 4


Rob's solution - looking at the button - looks like a viable approach.

Also, feel free to take a look at my Easy Tabs v5 code:


In the case of the Easy Tabs, I used a different approach because I needed the code to work in both SP 2007 and SP 2010. Here are the tests I included:

p.getAttribute("contenteditable")=="true"; //(where p is a Web Part zone)
document.forms[0].elements["_wikiPageMode.value"]=="true"; //(wiki page)
  • "Feel free to take a look". I love easy tabs!
    – Kevin
    Sep 15, 2010 at 11:50

I found Amal Hashim's blog post: Javascript Detect SharePoint Page In Edit Mode There are different approaches for pages, wikis and publishing pages. I combined them into one helper function:

function isEditMode() {
    var publishingEdit = window.g_disableCheckoutInEditMode,
        form = document.forms[MSOWebPartPageFormName],
        input = form.MSOLayout_InDesignMode || form._wikiPageMode;  
    return !!(publishingEdit || (input && input.value));

This returns true if the page is being edited, and false if the page is in the view mode.


A somewhat cheesy approach is to look for an element on the page that exists when the page is in edit mode. For example, when in edit mode the "Editing Tools" ribbon appears and there is a save icon off to the left. If you use the IE developer tools, you'll see the code for the save button looks like this:

So using jQuery you can check for the existence of "Save & Close" on the page...or choose a different element entirely -- one that is unique.

Keep in mind that different page types (blogs, wikis, web part pages) may or may not use different tags so this may not work across the board. So double-check the page you're working with before you include the script.

  • I'm hoping there's something more standardized, but that's certainly a viable solution.
    – Kevin
    Aug 18, 2010 at 18:20
  • I'd love to see a more standard solution myself. I'm eagerly watching to see if anyone else has ideas.
    – Rob Wilson
    Aug 18, 2010 at 19:28

Found more info. If you want to do it through the object model, see if either of these links helps:


Some example implementations of the aforementioned class: http://mystepstones.wordpress.com/2008/09/23/detecting-the-current-mode-displayedit/

  • 1
    Those are cool, certainly, but they're server side controls and I want a strictly using a CEWP. At this point, it seems like my best bet may be to use these server side controls in my master page to emit a variable I can test in my javascript. Rob, I genuinely appreciate you taking the time to provide two ideas.
    – Kevin
    Aug 18, 2010 at 20:32
  • My pleasure, Kevin. Feel free to post your own answer on here when you are finished for others to reference.
    – Rob Wilson
    Aug 18, 2010 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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