Menu
Hi all,
I am having an issue with a script which fails when the internet connection is lost, and so it should.
Is there a way that the web page can be automatically refreshed if the connection is lost using JavaScript. I need to continually refresh until the connection is back on.
I know all about META refresh but that does not help.
Any advice you can give would be great.
Best regards,
Dereck
Is there a way that the web page can be automatically refreshed if the connection is lost using JavaScript. I need to continually refresh until the connection is back on.[/quote]
<script type='text/javascript'>
(function ( img, wait, notify )
{
var iObj = new Image();
iObj.onerror = function()
{
if( notify )
alert( 'reloading' );
location.reload( true );
}
iObj.onload = function()
{
setTimeout( test, wait );
}
function test()
{
iObj.src = img + '?t=' + new Date();
}
test();
})( 'myimage.gif', 2000, true );
// 'myimage.gif' = URL of a small image present on your server
// 2000 = milliseconds between tests
// true/false = display confirmation alert before reload
</script>
Is there any way to stop the alert from displaying and just let the script run.[/quote]I explained that in the notes at the end of the script.
[CODE]
if( notify )
alert( 'reloading' );
location.reload( true );
}
[/CODE]
[CODE]
})( 'myimage.gif', 2000, true );
[/CODE]
<i>
</i><script type='text/javascript'>
(function ( img, wait, notify )
{
var iObj = new Image();
iObj.onerror = function()
{
if( notify )
alert( 'reloading' );
location.reload( true );
}
iObj.onload = function()
{
setTimeout( test, wait );
}
function test()
{
iObj.src = img + '?t=' + new Date();
}
test();
})( 'images/myimage.gif', 2000, false );
// 'myimage.gif' = URL of a small image present on your server
// 2000 = milliseconds between tests
// true/false = display confirmation alert before reload
[CODE]location.reload( true );
[/CODE]
[CODE]<script type='text/javascript'>
var hasConnectionBeenLost = false;
(function ( img, wait, notify )
{
var iObj = new Image();
iObj.onerror = function()
{
if( notify )
alert( 'reloading' );
hasConnectionBeenLost = true;
setTimeout( test, wait );
//display some message to user connection is lost
//document.getElementById("someElementMessage").style.display="block";
}
iObj.onload = function()
{
if(hasConnectionBeenLost){
location.reload( true );
)
else{
setTimeout( test, wait );
}
}
function test()
{
iObj.src = img + '?t=' + new Date();
}
test();
})( 'images/myimage.gif', 2000, false );
// 'myimage.gif' = URL of a small image present on your server
// 2000 = milliseconds between tests
// true/false = display confirmation alert before reload[/CODE]
Hi Logic Ali,
Sorry to be a pain in the neck.
I am not to sure if the true/false is changed in:
or
<i>
</i>if( notify )
alert( 'reloading' );
location.reload( true );
}
and my last question, should the script to in the iFrame or its parent page.
<i>
</i>})( 'myimage.gif', 2000, true );
Again, many thanks for all your time.
Dereck[/quote]
<script type='text/javascript'>
(function ( img, ifId, wait, notify )
{
var iObj = new Image(),
theIframe = document.getElementById( ifId ),
ifHref = theIframe.contentWindow.location.href;
iObj.onerror = function()
{
dt( 'Attempting iframe reload @ ' + new Date().getTime() );
try{ theIframe.contentWindow.location.href = ifHref; }catch( e ){ dt( 'Access Error ' + new Date().getTime() ); };
setTimeout( test, wait );
}
iObj.onload = function()
{
dt( 'Load OK' );
setTimeout( test, wait );
}
function test()
{
try{ ifHref = theIframe.contentWindow.location.href; }catch( e ){};
iObj.src = img + '?t=' + new Date().getTime();
}
function dt(s){ if(notify)document.title = s;}
test();
})([B] 'myimage.gif', 'if1', 2000, true[/B] );
</script>
There are now 4 parameters. The second is the ID of the target iframe. Instead of alerting when the last parameter is set to [FONT=Courier New]true[/FONT], messages appear in the title bar instead (document must have a <title> set).<i>
</i><?php
if (!isset($_SESSION)) {
session_start();
}
$date = date("l jS F Y", time());
$time = date("h:i A", time());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Project page</title>
<script type='text/javascript'>
(function ( img, ifId, wait, notify )
{
var iObj = new Image(),
theIframe = document.getElementById( ifId ),
ifHref = theIframe.contentWindow.location.href;
iObj.onerror = function()
{
dt( 'Attempting iframe reload @ ' + new Date().getTime() );
try{ theIframe.contentWindow.location.href = ifHref; }catch( e ){ dt( 'Access Error ' + new Date().getTime() ); };
setTimeout( test, wait );
}
iObj.onload = function()
{
dt( 'Load OK' );
setTimeout( test, wait );
}
function test()
{
try{ ifHref = theIframe.contentWindow.location.href; }catch( e ){};
iObj.src = img + '?t=' + new Date().getTime();
}
function dt(s){ if(notify)document.title = s;}
test();
})( 'images/myimage.gif', 'if1', 2000, true );
</script>
<link href="css/boardsstyle.css" rel="stylesheet" type="text/css" />
</head>
<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" >
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="wrapper">
<tr><td width="24%" valign="middle" bgcolor="#FFFFFF">&nbsp;</td>
<td width="56%" valign="middle" bgcolor="#FFFFFF" class="mainheader"><div align="center"> DEPARTURES</div></td>
<td width="20%" align="center" bgcolor="#FFFFFF" class="timedate"><img src="images/myimage.gif" width="1" height="1" border="0" /><?php print $date; ?></td>
</tr>
<i> </i> <tr>
<i> </i> <td height="100%" colspan="3" align="center"><iframe id="if1" src="departframe.php" width="100%" frameborder="0" marginheight="0" marginwidth="0" scrolling="no" ></iframe></td>
<script type="text/javascript">
function resizeIframe() {
var height = document.documentElement.clientHeight;
height -= document.getElementById('if1').offsetTop;
height -= 20;
document.getElementById('if1').style.height = height +"px";
};
document.getElementById('if1').onload = resizeIframe;
window.onresize = resizeIframe;
</script>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<i> </i></table>
<i> </i> </td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($arrive);
?>
If the internet connection is disabled the page continues to display until the iframe calls for its refresh. When this happens the main page is still displayed but the iframe page is blank with the message "Internet Explorer cannot display the webpage"You're running the code before the iframe is rendered.
I then enable the internet connection but the ifame is not reloaded.
[/quote]
<i>
</i>(function ( img, ifId, wait, notify )
{
var iObj = new Image(),
theIframe = document.getElementById( ifId ),
ifHref = theIframe.contentWindow.location.href;
iObj.onerror = function()
{
dt( 'Attempting iframe reload @ ' + new Date().getTime() );
try{ theIframe.contentWindow.location.href = ifHref; }catch( e ){ dt( 'Access Error ' + new Date().getTime() ); };
setTimeout( test, wait );
}
iObj.onload = function()
{
dt( 'Load OK' );
setTimeout( test, wait );
}
function test()
{
try{ ifHref = theIframe.contentWindow.location.href; }catch( e ){};
iObj.src = img + '?t=' + new Date().getTime();
}
function dt(s){ if(notify)document.title = s;}
test();
})( 'images/myimage.gif', 'if1', 2000, true );
I have openned a new thread because I am still having a issue with the code[/QUOTE]Don't do this, users can not follow the thread history, always bump your existing thread.
<i>
</i><iframe id="if1" src="departframe.php" </iframe>
(function ( img, if1, wait, notify )
{
var iObj = new Image(),
theIframe = document.getElementById( if1 ),
<i> </i> ifHref = theIframe.contentWindow.location.href;
iObj.onerror = function()
{
dt( 'Attempting iframe reload @ ' + new Date().getTime() );
try{ theIframe.contentWindow.location.href = ifHref; }catch( e ){ dt( 'Access Error ' + new Date().getTime() ); };
setTimeout( test, wait );
}
iObj.onload = function()
{
dt( 'Load OK' );
setTimeout( test, wait );
}
function test()
{
try{ ifHref = theIframe.contentWindow.location.href; }catch( e ){};
iObj.src = img + '?t=' + new Date().getTime();
}
function dt(s){ if(notify)document.title = s;}
test();
})( 'images/myimage.gif', 'if1', 2000, true );
0.1.9 — BETA 5.17