5

i have a webpage which is housing my iFrame which is from a different domain. Now i have a button inside the iFrame which when pressed, needs to refresh or reload the iframe.

I've tried a few methods which are blocked due to cross domain attempts..

Thirumalai murugan
  • 5,698
  • 8
  • 32
  • 54
Dustin Silk
  • 4,320
  • 5
  • 32
  • 48
  • 1
    What actually have you tried? Is the button calling JS code included within the iframe's document? – nnnnnn Jun 25 '13 at 11:55
  • 1
    `window.location.reload()` ? – Bergi Jun 25 '13 at 11:57
  • 2
    I disagree that this question is a duplicate of https://stackoverflow.com/questions/2064850/how-to-refresh-an-iframe-using-javascript because this question is specifically about reloading from the document within the iframe, whereas that other question is about reloading from the parent document containing the iframe. – quantoid Jul 25 '18 at 02:11

1 Answers1

14

In your script within the iframe, try this:

document.location.href = document.location.href;

You can't access elements outside of your document model from within the iframe, including accessing the iframe itself. You can access the properties of the document within it however.

Rob Hardy
  • 1,821
  • 15
  • 15
  • Worked for me on a similar problem where I had a form in the same domain in an iframe that wasn't reloading right in IE 11 and I had been working on it for over an hour when I saw this and I had a Eureka! moment (well, okay, it wasn't quite THAT dramatic, but it was a bright spot in an otherwise dull Monday at work) – Realto619 May 05 '14 at 19:38
  • This worked for me reloading an iframe from inside the iframe. – jessier3 Jul 07 '16 at 15:11