Reload IFrame and manage Same-Origin policies with JQuery

jquery-logoFor 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 :


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.

Published by Emmanuel Istace

Musician, Software developer and guitar instructor.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: