Currently, I have a JavaScript code snippet on my website that automatically refreshes an iframe every three seconds.
window.setInterval(function() {
reloadIFrame()
}, 3000);
function reloadIFrame() {
var frame = document.getElementById("iframe");
var len = frame.getElementsByTagName("TABLE").length;
if ( len == 0 ){
console.log('reloading..');
document.getElementById('iframe').contentWindow.location.reload();
}
}
However, I am facing an issue where the function continues to run even when there is a table present in the iframe. I would appreciate any suggestions or insights on how to prevent the function from executing when a table is detected.
(For context, the iframe I am referring to is most likely local on localhost:8000. I am using Django, and this code is part of a template.)