user5858
user5858

Reputation: 1221

Browser should keep refreshing the iframe -- not working

I've a page which shows network status. It is refreshing it self after 1 minute or so. But when it can't load page it simply display blank page and stays there even when it could load the page.

To solve it I've placed this network status page(status.php) within an iframe and that the parent page(index.html) should keep reloading the network status page within iframe after 1-2 minutes.

I've written this code:

<!DOCTTYPE html>
<head>

<script>

console.log("Running window.log");
window.setInterval(function(){
reloadIFrame();
}, 10000);

function reloadIFrame() {
console.log("reloaded the frame");
 window.frames[0].location.reload();
}

</script>
</head>

<body>
<iframe  frameborder=0 name="frame11" width="100%" height="100%" src="status.php">
</iframe>

Now when I disable network connection, this is page(index.html) is going blank showing on Chrome: "The Internet connection has been lost." with message in console:

Uncaught SecurityError: Blocked a frame with origin "http://upordown.example.com" from accessing a frame with origin "null". The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "data". Protocols must match.

How to solve this problem? That parent page should keep loading child frame and at least parent frame should work whether or network connection is there or not.

Upvotes: 0

Views: 454

Answers (1)

user5858
user5858

Reputation: 1221

This code has made it work:

window.setInterval(function(){
reloadIFrame();
}, 90000);

function reloadIFrame() {

var url = "status.php"+"?rand="+new Date().getTime();

$.get( url, function( data ) {
  $( "#frame1" ).html( data );
  $("#frame1").contents().find('html').html(data);

});
}

Upvotes: 0

Related Questions