1

I tried to reload the iframe window using JS but haven't had any luck getting the lp-iframe iframe element, I was thinking I could do it using the Window.Craft object but not sure how?

setTimeout(()=>{
  var iframe = document.querySelector('.lp-iframe');
  iframe.contentWindow.location.reload();
}, 5000);
2

All you need to do is

Craft.livePreview.updateIframe(true);

to update the Live Preview iFrame

  • It tells me that Craft is not defined? I tried Window.Craft and Craft and also putting this in a setTimeout – user2315552 Mar 22 '18 at 12:19
  • You can only use that in your CP. There is actually no way that Craft is not defined, otherwise your entire CP would not work. Of course you have to include your file after all Craft assets. Please make sure to implement your code after the livePreview is initialized. Are you using Craft 3 or Craft 2? – Robin Schambach Mar 22 '18 at 12:21
  • Hey I'm using Craft 3, if I console.log the live preview iframe I see there isn't a Craft object but that's only within the CP context. Is there a way to trigger a refresh from within the page that is being previewed? – user2315552 Mar 22 '18 at 12:26
  • Never mind I got it working using window.parent.Craft.livePreview.updateIframe(true); – user2315552 Mar 22 '18 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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