refresh iframe from inside itself with different domains

12,869

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.

Share:
12,869

Related videos on Youtube

Dustin Silk
Author by

Dustin Silk

Updated on June 04, 2022

Comments

  • Dustin Silk
    Dustin Silk almost 2 years

    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..

    • nnnnnn
      nnnnnn almost 11 years
      What actually have you tried? Is the button calling JS code included within the iframe's document?
    • Bergi
      Bergi almost 11 years
      window.location.reload() ?
    • quantoid
      quantoid almost 6 years
      I disagree that this question is a duplicate of stackoverflow.com/questions/2064850/… 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.
  • Realto619
    Realto619 almost 10 years
    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)
  • jessier3
    jessier3 almost 8 years
    This worked for me reloading an iframe from inside the iframe.