?
Solved

How to detect internet connection with jQuery?

Posted on 2008-10-31
5
Medium Priority
?
2,031 Views
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?
0
Comment
Question by:koleto115
[X]
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
5 Comments
 
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.src="http://someimageonthenet.com/jpg.jpg";
image.onload=function () {  connection=true; }
0
 

Author Comment

by:koleto115
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 ....
0
 
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 :)
0
 

Author Comment

by:koleto115
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 ... ;)
0
 
LVL 18

Accepted Solution

by:
Pawel Witkowski earned 375 total points
ID: 22849119
0

Featured Post

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
Suggested Courses

801 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