How to detect internet connection with jQuery?

Posted on 2008-10-31
Last Modified: 2012-05-05
I am using web services on a web site that can also run in a local machine. Is there any standard way in form of an elegant jQuery script to detect whether the internet connection is available?
Question by:koleto115
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 22848423
You can try by loading image from internet:

var connection=false;
var image=new Image();
image.onload=function () {  connection=true; }

Author Comment

ID: 22848711
What will happen when the url of the image is change or removed?
Furthermore this is not jQuery call. There should be kind of utility function not related to resource on the internet that can be changed ....
LVL 18

Expert Comment

by:Pawel Witkowski
ID: 22848866
Nope there is not... jQuery is only a Javscript libary - it iteslf cannot do what javscript cant too. This not have to be image.. but anything that is internet and you sure that it will be there... If someone other got better idea... Then i really curious :)

Author Comment

ID: 22848930
There is utilities for detecting the browser, there should be something ...
I know that Ajax makes only http request but ... I am curious too ... ;)
LVL 18

Accepted Solution

Pawel Witkowski earned 125 total points
ID: 22849119

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Github api to fetch the number of collaborators in a git repo 1 29
Compute age Html 2 26
Put POST values into cookies. 14 34
HTML editor custom button 3 58
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question