For a project, I had to dynamicaly reload an IFrame (within a JQuery dialog box) and include cross domain pages.
To load the IFrame and set the source :
$(FrameID).attr("src", URL);
To reload the IFrame you can use :
$(FrameID).contentDocument.location.reload(true);
But if the content come from another domain you will be denied access to the iframe’s contentDocument property due to the same-origin policy.
To force the cross-domain iframe to reload if your code is running on the iframe’s parent page, you can set it’s src attribute to itself.
var iframe = document.getElementById(FrameID); iframe.src = iframe.src;
But be carefull, this is a hack ! So if you do something like this in production code, comment it, or the next one would probably remove this code who seems totally useless.
still this solution shows cross domain error
Yeah, sorry, might be outdated 7 years later, was really a hackish way to get around an hackish solution, if possible, I wouldn’t recommend at all using iframe (even for 2013, don’t remember why, but was probably integration with some stuff I don’t have hands on) and if you have CORS issues, might consider taking a look at your server config/http header (or if not possible, look for a “cors proxy”, still hackish, but perhap’s “less messy”) π
Hope you’ll find a (clean) solution ! π