Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript - Check Internet Connection using jQuery Example

Mar 28, 2013
Introduction

Here I will explain how to check internet connection using
jQuery / JavaScript or Check internet connection with JavaScript.

Description:
  
In previous articles I explained JavaScript remove duplicate values from arraylist,
jQuery change background color randomly, jQuery create rounded corner textbox, JavaScript Show number of characters left in textbox and many articles relating to JQuery, JavaScript and asp.net. Now I will explain how to check internet connection using jQuery or JavaScript.

To implement this functionality we need to write the following code like as shown below


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Check Internet Connection using jQuery</title>
<script type="text/javascript">
function checkconnection() {
var status = navigator.onLine;
if (status) {
alert("online");
} else {
alert("offline");
}
}
</script>
</head>
<body>
<div>
<input type="button" value="Check Connection" onclick="checkconnection()" />
</div>
</body>
</html>
Live Demo

If you want to check live demo click on below button to know about your connection status



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

15 comments :

Anonymous said...

Please add a brief information which will help the readers to know the concepts clearly.

Rakesh said...

Nice3 One

Unknown said...

Sorry its not work help me.....please

HANUMA KARTHI said...

Wonder full job for beginners

paris said...

Wonderful advice and now i know how to Check internet connection!!! Thanks.

Developers Helper said...

Hi Suresh,
I need to detect whether Internet connection is there when my script loads, i used navigator.online it says" connection is there " if the PC in LAN and able to connect to internet, and also the path to my Gmap js files should load according the connection settings online and offline settings intially i tried

$(document).ready(function () {
$.ajax({
url: 'http://in.yahoo.com/',
success: function (data) {
alert('Connection.');
},
error: function (data) {
alert('No Connection.');
}
});
});

but this is also not working.

iam getting error like XMLHttpRequest cannot load http://in.yahoo.com/. Origin http://localhost:40624 is not allowed by Access-Control-Allow-Origin.

For which i added

protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
}
in my Global.asax file

PLs suggest me any idea.Really a challenging one

Anonymous said...

This doesn't work in Firefox.

Anonymous said...

This is a pile of poopoo. It is only for beginners and not a proper way to check. If you want real answer go to stackoverflow and you will find PROPER solution, not rubbish like this

Anonymous said...

Not working at offline mode

Unknown said...

Yes that's not working

Unknown said...

Always returns true , Not Working

Unknown said...

Great work! really helped me!

Unknown said...

working on IE but not on Crome and Firox.

Unknown said...

always "online"

Anonymous said...

Thankyou so much..awesome

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.