Answers.Body: <p>All you need to do is</p>
  
  <pre><code>Craft.livePreview.updateIframe(true);
  </code></pre>
  
  <p>to update the Live Preview iFrame</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T12:19:27.813Z
Answers.Text: It tells me that Craft is not defined? I tried Window.Craft and Craft and also putting this in a setTimeout
Answers.UserDisplayName: Jai Sandhu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T12:21:36.543Z
Answers.Text: 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?
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T12:26:25.897Z
Answers.Text: 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?
Answers.UserDisplayName: Jai Sandhu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-22T12:34:18.183Z
Answers.Text: Never mind I got it working using `window.parent.Craft.livePreview.updateIframe(true);`
Answers.UserDisplayName: Jai Sandhu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-21T22:08:55.217Z
Answers.LastActivityDate: 2018-03-21T22:35:47.907Z
Answers.LastEditDate: 2018-03-21T22:35:47.907Z
Answers.UserDisplayName: Robin Schambach
Body: <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>
  
Tags: <javascript><live-preview>
Title: How can I reload the Live Preview Iframe window using JS
ThreadText: # 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);`  
  
  ---
  
  