/    Sign up×
Community /Pin to ProfileBookmark

Refreshing web page until a connection is restored

Hi,

Sometime ago I was working on a script that continually refreshed the browser if the connection was lost with the server. The help I received was great and I thank all those people who took the time to lend a hand.

I have now got the same issue with a slight difference, the script below refreshed an iFrame which works fine.

My question is can this script be made to work on a normal web page (without an iFrame).

[code]
<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();

})( ‘myimage.gif’, ‘if1’, 2000, true );

</script>
[/code]

Many thanks if you can spare the time to help.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@omnicityFeb 23.2012 — I think you probably can, but there is one key problem to work around, which is that when you successfully load a page, you lose the current code, and so have no obvious way or recording success!

Might need to have the page provide a time-stamp within it, or try using HTML5 Local-Storage to store a time-stamp.
Copy linkTweet thisAlerts:
@rnd_meFeb 24.2012 — don't refresh the page, ping the server and alter the UI according to the connection state.
Copy linkTweet thisAlerts:
@NoEffinWayFeb 25.2012 — ...how would it get the JS if it cannot connect in the first place..?
Copy linkTweet thisAlerts:
@dcjonesauthorFeb 25.2012 — Hi all,

Hi NoEffinWay,

Very good point, for whatever reason I did not think of that.

All I am trying to do is force the browser to refresh if the internet connection drops for a seconds or two.

Do you have any ideas on how this could be done.

Many thanks for any help or pointer your or anyone can give.

Best regards,

Dereck
Copy linkTweet thisAlerts:
@NoEffinWayFeb 25.2012 — AJAX based navigation would work...not vary practical but seems to be the only option for what you are wanting other than frames.
Copy linkTweet thisAlerts:
@rnd_meFeb 25.2012 — navgator.onLine changes when the connection drops. there's an event too, but it's not as widely supported, so it might be best to poll navigator.onLine.

in terms of connecting without internet, you need to use a manifest attrib on your html tag. Of course, you have to connect once to the site with internet, duh, but then you can repeat visit without connectivity.
×

Success!

Help @dcjones spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...