Javascript code to detect loss of internet connectivity

I am writing a web based chat service much like the one here:
http://code.jenseng.com/jenChat/

My question is this, if you look at that example, it uses a hidden iFrame that auto-refreshes itself then writes any new chat lines it pulls to the main menu, which works great, until the client looses their internet connection. Then the auto-refreshing iFrame turns into a page cannot be displayed error, and no further lines in the chat are displayed since that page is no-longer auto-refreshing. My question becomes what would be the best way to detect that the frame is no longer refreshing and force a reload every 5-10 seconds until the connection resumes itself, then of course the iFrame's own refresh would take over? This has to assume a complete loss of internet connectivity, so I would assume it would be a bit of javascript in the main page that does not auto-refresh, so it would continue to work even if a loss of connectivity is experienced.

Any help in the right direction would be appreciated, thank you!
NeoGeminiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

robotman757Commented:
You can try soemthing like this...create a variable and then get the html of the iFrame.
var txt = window.frames["youriframe"].innerHTML;
check the txt variable for "The page cannot be displayed"...if it contains this text, tell the script to refresh, and if not then do nothing. I can see this working in my head, but have no way to test it, so I am not totally sure..
0
ZvonkoSystems architectCommented:
My idea would be to pleace something at the beginning of every content returned to the iframe, something like a content title.
If the title is not there, then is the content not comming from the server, then the output should be suppressed and the refresh rate lowered.

Of course does the title not need to be displayed to the user.

0
Andrea ErcolinoCommented:
you could put the IFRAME content in another invisible container and then copy it to the visible one if it's valid
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Andrea ErcolinoCommented:
the validity check could be in the content itself... a function call at the end of the body will do
that function (refreshVisible) should be declared in the main container and should do the following
1. copy the content of the invisible container to the visible IFRAME --> if there is a page error, then there is no function call, then there is no visible refresh, and no error shown
2. reset a timer for calling a new function (refreshHidden) in two seconds --> if there is a page error, then there is no function call, then the timer will continue to run and possibly call the refreshHidden function upon expiration
3. you'll need a check at the beginnig fro preventing execution when called from the visible container rather than the hidden one

it's just an idea...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MatrixDwellerCommented:
You could have a timer on the main page that checks the value of a variable on the popup. If the variable is there then the window is good. If not then the window is bad then close it.
0
NeoGeminiAuthor Commented:
I'm working on these ideas, RAPUTA your idea seems the most promising, can you expand a little on your explanation? I greatly appreciate it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.