I have a page which contains an iframe.
My problem is that I sometimes need to modify the iframe's page but the changes are not showing on the main page unless I go to that frame and reload it manually.
Is there a way to refresh the iframe when the page loads or similar way to sort this problem?
3 Answers 3
You could do on document ready:
$(document).ready(function() {
$('#your_iframe_id').attr( 'src', function ( i, val ) { return val; });
});
Did you mean like that
Comments
Re-setting the src attribute of the iframe is sufficient to cause it to reload. For example:
$(function() {
$('#idOfIFrame').attr('src', 'http://yourDomain.tld/yourPage');
});
Will cause the iframe to load http://yourDomain.tld/yourPage.
Alternatively, if the iframe src is on the same domain as the outer page, you can trigger a refresh by the following:
document.getElementById('idOfIFrame').contentDocument.location.reload(true);
Comments
Providing the iframe is on the same domain as the parent page, the following JavaScript will perform a reload:
document.getElementById('iframeID').contentDocument.location.reload(true);
You can use that whenever you need to refresh it.