<p>All you need to do is</p>

<pre><code>Craft.livePreview.updateIframe(true);
</code></pre>

<p>to update the Live Preview iFrame</p>

CC BY-SA 3.0
2018-03-22T12:19:27.813Z
It tells me that Craft is not defined? I tried Window.Craft and Craft and also putting this in a setTimeout
Jai Sandhu
CC BY-SA 3.0
2018-03-22T12:21:36.543Z
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
CC BY-SA 3.0
2018-03-22T12:26:25.897Z
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?
Jai Sandhu
CC BY-SA 3.0
2018-03-22T12:34:18.183Z
Never mind I got it working using `window.parent.Craft.livePreview.updateIframe(true);`
Jai Sandhu
CC BY-SA 3.0
2018-03-21T22:08:55.217Z
2018-03-21T22:35:47.907Z
2018-03-21T22:35:47.907Z
Robin Schambach
<p>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?</p>

<pre><code>setTimeout(()=&gt;{
  var iframe = document.querySelector('.lp-iframe');
  iframe.contentWindow.location.reload();
}, 5000);
</code></pre>

<javascript><live-preview>
How can I reload the Live Preview Iframe window using JS
# How can I reload the Live Preview Iframe window using JS

(Asked by: username_0 on 2018-03-21)

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);

**Tags:** javascript, live-preview


---

## 1 answers

### Answer by username_1 on 2018-03-21. Score: 2 | Accepted answer

All you need to do is
Craft.livePreview.updateIframe(true);

to update the Live Preview iFrame

> **Comments:**
> **username_0**: It tells me that Craft is not defined? I tried Window.Craft and Craft and also putting this in a setTimeout  
> **username_1**: 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?  
> **username_0**: 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?  
> **username_0**: Never mind I got it working using `window.parent.Craft.livePreview.updateIframe(true);`  

---

