Friday, February 14, 2020

What is the best way to reload (or) refresh an iframe using JavaScript?

Solution 1:

document.getElementById('iframeid').contentWindow.location.reload();

be careful, in Firefox, window.frames[] cannot be indexed by id, but by name or index.

Solution 2:

document.getElementById('iframeid').src = document.getElementById('iframeid').src;

It will reload the iframe, even across domains! Tested with IE7/8, Firefox and Chrome.

Solution 3:

If using jQuery, this seems to work:

$('#iframeid').attr('src', $('#iframeid').attr('src'));

No comments:

Post a Comment