Is there a way to disable a javascript init block from executing in the Page Edit interface?

James Jarrett asked on March 3, 2015 17:00

I'm trying to integrate wow.js into our pages but what I didn't expect is that the wow init block is executing in the Page Edit interface and adding the additional wow attributes over and over again every time the page is saved to the editable text regions.

Could I use a role macro to only have this block of javascript executed only on the live site?

Is there a better approach? Just looking for some ideas before I spend too much time in one direction.

Correct Answer

Brenden Kehren answered on March 3, 2015 17:21

If you are using the JavaScript webpart, it automatically disables it. I'd suggest going that route.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Virgil Carroll answered on March 3, 2015 17:21

Where are you implementing the JavaScript? in the Master Page?

I would think an easier route would be to use some jQuery on the Init Block to make sure there isn't some element of the DOM showing up on the page. For instance, when in Page Edit mode Kentico tacks on the cmsedit.js file. You could look for that and if present not perform the Init block of code.

That is just an example, you could also use the container that holds the page in the page edit interface, etc. This would be much less impactful on your system vs a macro and be easy to implement. We do this type of look often in both Kentico and non-Kentico type systems.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on March 3, 2015 18:40

As Brenden recommended, use the JavaScript web part. I also do it another way, this is actual code that check's what view mode I am in and then disables or enables. Customize it to your needs. This is at the bottom of my Master page. Specifically I toggle a bootstrap navigation javascript web part on and off so I can see it correctly between the live and edit mode.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on March 3, 2015 18:40 (last edited on March 3, 2015 19:03)

<script runat="server">
  protected override void OnInit(EventArgs e)
{
      string CurrentViewMode= CMS.PortalEngine.PortalContext.ViewMode.ToString();

      if ( CurrentViewMode== "LiveSite" )
      {

        TopNavBarFixed.Visible= true;
        TopLiveCushion.Visible= true;

      }
    }
}
0 votesVote for this answer Mark as a Correct answer

James Jarrett answered on March 3, 2015 19:10

All of those are great suggestions. It is a jQuery document ready block. I've never had a problem with a script init before in this manner. I will rework the script into a JavaScript web part.

I will also look into the code Charles posted. I can see that potentially being useful in the future.

0 votesVote for this answer Mark as a Correct answer

Charles Matvchuk answered on March 3, 2015 19:33 (last edited on March 3, 2015 19:34)

To further elaborate on my code, what I am toggling is a place holder. So basically you can put anything in placeholders and toggle them depending on the view mode you are in.

'<asp:Placeholder ID="TopLiveCushion" runat="server" visible="false" >
  <div style="width:100%;height:50px">
  </div>
</asp:Placeholder>'
0 votesVote for this answer Mark as a Correct answer

Anthony Levine answered on November 22, 2016 17:35

I'm having a similar issue. I'm using a Javascript web part with in-line Javascript making some edits after page load (utilizing JQuery's document.ready). But when I go to the Page tab to an editable text control, I'm prevented from doing so. The Javascript has obviously ran since text is appended to a different div on the page. It's not until I disable that web part on the Design tab that I can edit on the Page tab. Is there a specific reason this is happening since Javascript web parts are not supposed to run on the Page tab?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.