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.
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. |
|||
|
|||
15 comments :
Please add a brief information which will help the readers to know the concepts clearly.
Nice3 One
Sorry its not work help me.....please
Wonder full job for beginners
Wonderful advice and now i know how to Check internet connection!!! Thanks.
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
This doesn't work in Firefox.
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
Not working at offline mode
Yes that's not working
Always returns true , Not Working
Great work! really helped me!
working on IE but not on Crome and Firox.
always "online"
Thankyou so much..awesome
Note: Only a member of this blog may post a comment.