I would like to reload an using JavaScript. The best way I found until now was set the iframe’s
src
attribute to itself, but this is
Use reload for IE and set src for other browsers. (reload does not work on FF) tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
For debugging purposes one could open the console, change the execution context to the frame that he wants refreshed, and do document.location.reload()
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)