<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Preventing JS from loading in the Page Editor in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/295776#M13886</link>
    <description>&lt;P&gt;The solution has been provided by the support team, they pointed me to this article.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://designers.hubspot.com/how-to-make-custom-code-work-with-cms" target="_blank"&gt;https://designers.hubspot.com/how-to-make-custom-code-work-with-cms&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to use window.hsInEditor provided the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my instance it was just a matter of checking window.hsInEditor in the conditional.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;jQuery(document).ready(function(){
    if( window.hsInEditor ) {
        return;
    } else {
        jQuery('.slick-group').slick({});
    }
});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Worked a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 09 Oct 2019 14:57:20 GMT</pubDate>
    <dc:creator>eldin</dc:creator>
    <dc:date>2019-10-09T14:57:20Z</dc:date>
    <item>
      <title>Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/295708#M13874</link>
      <description>&lt;P&gt;I have inserted a &lt;A href="https://kenwheeler.github.io/slick/" target="_self"&gt;Slick&lt;/A&gt;&amp;nbsp;carousel into a page template in the "Additional markup before &amp;lt;/body&amp;gt;". It works great while viewing the page, but the problem I am facing is in the editor, the script also runs when rendering the page therefore preventing me from editing the original content as the slick construct modifies the content to display it as a carousel (not desired).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attempted to prevent the script from running by checking if the body tag contains the&amp;nbsp;&lt;SPAN&gt;hubspot-disable-focus-styles class, but the condition seems to be ignored when rendering in editor.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When running the script from the console, it does correctly detect the class and returns the correct boolean from the console in both the editor and out of editor page render. The if statement appears to be ignored and the script runs disregarding if the condition was met or not and triggers the slick construct from within the page editor.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;jQuery(document).ready(function(){
&amp;nbsp; if( jQuery('body.hubspot-disable-focus-styles').length ) {
&amp;nbsp; &amp;nbsp; &amp;nbsp;return false;
&amp;nbsp; } else {
&amp;nbsp; &amp;nbsp; &amp;nbsp;jQuery('.slick-group').slick();
&amp;nbsp; }
});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 10:57:59 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/295708#M13874</guid>
      <dc:creator>eldin</dc:creator>
      <dc:date>2019-10-09T10:57:59Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/295776#M13886</link>
      <description>&lt;P&gt;The solution has been provided by the support team, they pointed me to this article.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://designers.hubspot.com/how-to-make-custom-code-work-with-cms" target="_blank"&gt;https://designers.hubspot.com/how-to-make-custom-code-work-with-cms&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to use window.hsInEditor provided the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my instance it was just a matter of checking window.hsInEditor in the conditional.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;jQuery(document).ready(function(){
    if( window.hsInEditor ) {
        return;
    } else {
        jQuery('.slick-group').slick({});
    }
});&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Worked a treat.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Oct 2019 14:57:20 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/295776#M13886</guid>
      <dc:creator>eldin</dc:creator>
      <dc:date>2019-10-09T14:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/296024#M13901</link>
      <description>&lt;P&gt;Thank you for sharing this&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/107355"&gt;@eldin&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:43:34 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/296024#M13901</guid>
      <dc:creator>sharonlicari</dc:creator>
      <dc:date>2019-10-10T15:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/907558#M37493</link>
      <description>&lt;P&gt;This prevents the code running in the editor, but if you do not have jQuery on your website,&amp;nbsp;then the code will also not run on the web page. An error is thrown because jQuery is unknown.&lt;/P&gt;&lt;P&gt;I tried wrapping it in a try / catch statement, but that still ran in the editor (although the code does now work on the web page).&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 11:07:36 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/907558#M37493</guid>
      <dc:creator>ojobson</dc:creator>
      <dc:date>2024-01-18T11:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/907563#M37494</link>
      <description>&lt;P&gt;Solution found!! &lt;span class="lia-unicode-emoji" title=":white_heavy_check_mark:"&gt;✅&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have amended the recomended code on the support article to start the window onload check with native javascript (instead of jquery) and have tested it and it works well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;script&amp;gt;
window.onload = function() {
   if (window.hsInEditor) { 
      return; //stops running here when in the editor
   } else {
      //this code runs on your live website, but not in the editor
   }
}
&amp;lt;/script&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jan 2024 16:18:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/907563#M37494</guid>
      <dc:creator>ojobson</dc:creator>
      <dc:date>2024-01-18T16:18:53Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1049722#M40852</link>
      <description>&lt;P&gt;This works, but there's a Hubl solution:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% if !is_in_editor %}
// code snippets or files that need NOT loading when in page editor
{% endif %}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 03 Oct 2024 14:51:31 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1049722#M40852</guid>
      <dc:creator>ACBlack</dc:creator>
      <dc:date>2024-10-03T14:51:31Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1153294#M43044</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/184510"&gt;@ACBlack&lt;/a&gt;, where do you need to add this to work?&lt;/P&gt;</description>
      <pubDate>Fri, 16 May 2025 09:51:47 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1153294#M43044</guid>
      <dc:creator>LJanssens</dc:creator>
      <dc:date>2025-05-16T09:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: Preventing JS from loading in the Page Editor</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1153300#M43045</link>
      <description>&lt;P&gt;This comes to the module into the HTML/HuBL part since in the JS part you cannot use HubL.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 May 2025 10:11:37 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Preventing-JS-from-loading-in-the-Page-Editor/m-p/1153300#M43045</guid>
      <dc:creator>Albusis</dc:creator>
      <dc:date>2025-05-16T10:11:37Z</dc:date>
    </item>
  </channel>
</rss>

