/    Sign up×
Community /Pin to ProfileBookmark

how to know if there is internet connection

i would like to be able to know if there is internet connection

something like this

if (internet == true )
{

}else do something else

if it posibile to do something like this in javascript

thnx.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@KorSep 08.2009 — I used to think that I've seen everything possible on this Earth, but this question is above all ? How, by Hell, to see/run the javascript code placed in a web page [I]if you have no access to the Web[/I]?
Copy linkTweet thisAlerts:
@kujtimauthorSep 08.2009 — don't hury on your answers , what if you had a connection you load the page and then you lost it.

you click the link and you get the page could not be displayed message.

i would like to create a controlle thet checks the connection before redirect
Copy linkTweet thisAlerts:
@KorSep 08.2009 — Well, this is why there is a HTTP standard response code 404 error message ? Even so, that will tell you only that a link does not exist, but not why. On the other hand if you disconnect your LAN (or modem) different browsers have different responses: FF shows you an [B]Offline Mode[/B] message, Opera a [B]Could not locate remote server[/B] message, IE7 shows nothing, and so on... Anyway, as it is a client-side language, javascript can not detect the server-side changes, whichever they might be.
Copy linkTweet thisAlerts:
@tpircsavajSep 08.2009 — Tung Kujtim,

Let's assume that you're using AJAX and before you request some data from the server you want to know if the user has connection. I don't really see a need for this check as your initial request will either time-out or you'll receive the response code 404. And if you get one or the other then the user hasn't got the connection.

Anyway if you want to check for connection in your code if(internet) send an AJAX request and wait for response before redirecting.

Nese ke nevoj per ma shum ndihme dergom porosi private. Tung
Copy linkTweet thisAlerts:
@jalarieSep 10.2010 — I try to load an image that I know would be available if the 'net is connected and add an "onerror='notConnected();'" call in case there is no connection.
Copy linkTweet thisAlerts:
@DanInMASep 10.2010 — I used to think that I've seen everything possible on this Earth, but this question is above all ? How, by Hell, to see/run the javascript code placed in a web page [I]if you have no access to the Web[/I]?[/QUOTE]

you think this is bad? try working at a helpdesk....

"Should i type in my username where it says username?"

"the screen says to click on Next, what should I do?"

"why doesn't the computer turn on when I press the button on the monitor?"
Copy linkTweet thisAlerts:
@jalarieSep 10.2010 — My browser home page is set to a LOCAL (non-internet) page. It lists things I need to do today, checks for an internet connection, and lets me know what is or is not availble. This would be a totally worthless exercise if I were the one in charge of the connection, but life is not always what we wish it to be.
Copy linkTweet thisAlerts:
@OfekmeisterSep 10.2010 — [CODE]<html>
<head>
<script type="text/javascript">
<!--
function loadXMLDoc()
{

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

else
{// code for IE6, IE5

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

xmlhttp.onreadystatechange=function()
{

if (xmlhttp.readyState==0)
{

alert("You aren't connected!");

}

else if (xmlhttp.readyState==4)
{

alert("You are connected!");

}

}

xmlhttp.open("GET","http://www.w3.org/?t=" + Math.random(),true);
xmlhttp.send();

}
//-->
</script>
</head>
<body>

<button type="button" onclick="loadXMLDoc()">Check Connection</button>

</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@rnd_meSep 10.2010 — [CODE]alert(navigator.onLine)[/CODE]
Copy linkTweet thisAlerts:
@KorSep 13.2010 — [CODE]alert(navigator.onLine)[/CODE][/QUOTE]
Great ?
×

Success!

Help @kujtim spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...