• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2036
  • Last Modified:

How to detect internet connection with jQuery?

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
koleto115
Asked:
koleto115
  • 3
  • 2
1 Solution
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
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
 
koleto115Author Commented:
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
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
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
 
koleto115Author Commented:
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
 
Pawel WitkowskiSenior Javascript DeveloperCommented:
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now