CMS Development

ABrunot
Member

Issue with Javascript Code into page builder

SOLVE

Hi, I have an issue with a little piece of code only in page builder ( everything works fine on the "live" version of the pages"

 

I would like to add a page loader, which disappears when the page is loaded, pretty simple feature .. But when i'm in page builder, ( i guess ) the scipt is not executed, so the loader doesn't disappear 

 

$('body').append('<div style="" id="loadingDiv"><div class="loader">Loading...</div></div>');
$(window).on('load', function(){
  setTimeout(removeLoader, 2000); //wait for page load PLUS two seconds.
});
function removeLoader(){
    $( "#loadingDiv" ).fadeOut(500, function() {
      // fadeOut complete. Remove the loading div
      $( "#loadingDiv" ).remove(); //makes page more lightweight 
  });  
}

 

I have tried to hide it when when the body tag of the page has class .page-editor, but without success

 

Does anyone have an idea ? 

 

Thanks 🙂 

0 Upvotes
1 Accepted solution
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Issue with Javascript Code into page builder

SOLVE

@ABrunot @dennisedson I would wrap your script in an if statement like this:

if( window.hsInEditor ) {
  // do nothing if in the HubSpot page editor
  return;
} else {
  // put your scripts here
}
Stefen Phelps, Community Champion, Kelp Web Developer

View solution in original post

3 Replies 3
stefen
Solution
Key Advisor | Partner
Key Advisor | Partner

Issue with Javascript Code into page builder

SOLVE

@ABrunot @dennisedson I would wrap your script in an if statement like this:

if( window.hsInEditor ) {
  // do nothing if in the HubSpot page editor
  return;
} else {
  // put your scripts here
}
Stefen Phelps, Community Champion, Kelp Web Developer
ABrunot
Member

Issue with Javascript Code into page builder

SOLVE

It works, awesome ! I just had to remove the "return;" but it works . Thanks you 🙂 .

dennisedson
HubSpot Product Team
HubSpot Product Team

Issue with Javascript Code into page builder

SOLVE

@stefen , any words of advice here?

0 Upvotes