4

I am trying to force-reload the contents of an iframe (force-reload meaning the browser cache should not be used). From the soltuion Reload an iframe with jQuery here, I can do this via this javascript code:

document.getElementById(FrameID).contentDocument.location.reload(true);

But I am hitting the same-origin policy error. But I did enable CORS on both, the page that has the iframe embedded and the page that is loaded within the iframe. From the web development tools I have verified that on both loads, the CORS header is present:

Access-Control-Allow-Origin: *

Although both sides are under different domains, I control both of them and can send the CORS header or any other header, if required.

Whats the correct way of doing this?

Community
  • 1
  • 1
Dynalon
  • 6,085
  • 10
  • 50
  • 77

2 Answers2

2

Although this question is very old, it has a lot of views, so I'm going to link this nice trick here for developers with the same issue.

Andor Polgar
  • 443
  • 2
  • 12
0

CORS is not needed for the described case. The same origin policy doesn't allow accessing DOM properties and methods across different domains. You can use postMessage JavaScript API for enabling communication between IFRAME and parent page.

Alexander Pranko
  • 1,741
  • 16
  • 20