Reputation: 457
I'm using the following script to refresh my iframe. In case the refresh fails, it will show a different iframe:
<script type=text/javascript>
setInterval(function(){
var rq = new XMLHttpRequest();
rq.open('GET', document.getElementById('tracker').src, true);
rq.onreadystatechange = function() {
if(rq.readyState === 4) {
if(rq.status === 200) {
} else {
document.write('<iframe src="tracker2.html" style="border:0px #CCD1B9 none;" scrolling="no" frameborder="0" marginheight="0px" marginwidth="0px" height="407px" width="417px"></iframe>');
}
}
};
rq.send(null);
document.getElementById("tracker").src+="";
},2000);
</script>
My problem is below line: } else {
I would like to else, show a different iframe, but to keep reloading the main page again.
So to be clear: the above code is mainpage.html, and it will show iframe tracker2.html if it is unable to refresh iframe tracker.html, and I would like iframe tracker2.html to keep refrshing or REDIRECTING to mainpage.html every X seconds.
Upvotes: 0
Views: 433
Reputation: 3763
It seems like you should combine the logic of mainpage.html and tracker2.html together into one auto refreshing page but you may have your reasons not to do that.
Instead I suggest a meta refresh tag to help auto refresh the page:
<meta content="5; URL=/tracker2.html" http-equiv="Refresh" />
That will refresh after 5 seconds.
Upvotes: 2