Tuesday, December 24, 2013

Recently in my project I got a requirement where I have to switch views of web parts based on the page mode (browsing mode and edit mode). When user is in edit mode I have to show some styles which will give option to user to add the data easily, but when user save the changes and publish the page, the styles will go away and they see normal page. So, I have to identify whether the page is in Edit mode or Browse mode in javascript.

I have a set of styles already written and based on the page mode I need to add those styles to some divisions on html. To find the edit mode of the page using javascript we have to use below logic:
var IsPageInEditMode = 
if (IsPageInEditMode == "1") { 
    alert("web part page is in edit mode."); 
else { 
    alert("web part page is in browse mode."); 
But, this is not it all. To make it a common solution we must do more. :) The above logic works only for the Publishing pages. Which means if you have team pages (/sitepages/) or wiki pages then the above solution fails to return the correct value. For this, we should use below logic.
var IsPageInEditMode = document.forms[MSOWebPartPageFormName]._wikiPageMode.value; 
if (IsPageInEditMode == "Edit") { 
   alert("wiki page is in edit mode"); 
else { 
   alert("wiki page is not in edit mode"); 
These SharePoint hidden variables are handy most of the times. Let's take a closer look at how we did it.
SharePoint uses the form variable for all its operations. This is a global variable added by SharePoint Framework to javascript. See the below image:

If you see the above image, there are many variables available for you in javascript. The first one is what we have used to get the form name. And the same way, we have many hidden variables available in javascript. These all can be visible by doing "View Source" on your browser. :)

From one of my friend, I got to know that in SharePoint 2010, 2013 we have a method available to get the Page State.
var IsPageInEditMode = SP.Ribbon.PageState.Handlers.isInEditMode();
That's all for now. Enjoy the new findings. I know it's old finding but learning is always fun!



  1. Very helpful article ! I was always curious about all these complex algorithms that are being used in these encryptions.

  2. Earn from Ur Website or Blog thr PayOffers.in!


    Nice to e-meet you. A very warm greetings from PayOffers Publisher Team.

    I am Sanaya Publisher Development Manager @ PayOffers Publisher Team.

    I would like to introduce you and invite you to our platform, PayOffers.in which is one of the fastest growing Indian Publisher Network.

    If you're looking for an excellent way to convert your Website / Blog visitors into revenue-generating customers, join the PayOffers.in Publisher Network today!

    Why to join in PayOffers.in Indian Publisher Network?

    * Highest payout Indian Lead, Sale, CPA, CPS, CPI Offers.
    * Only Publisher Network pays Weekly to Publishers.
    * Weekly payments trough Direct Bank Deposit,Paypal.com & Checks.
    * Referral payouts.
    * Best chance to make extra money from your website.

    Join PayOffers.in and earn extra money from your Website / Blog


    If you have any questions in your mind please let us know and you can connect us on the mentioned email ID info@payoffers.in

    I’m looking forward to helping you generate record-breaking profits!

    Thanks for your time, hope to hear from you soon,
    The team at PayOffers.in