Autor | Zpráva | ||
---|---|---|---|
zacatecnik9 Profil |
#1 · Zasláno: 29. 3. 2009, 10:31:39
Zdravím,
nevíte prosím někdo, jak pomocí js, zkontroluji, zda-li mi nespadlo připojení na internet ? Potřeboval bych to mít na stránce, kterou před tím stáhnu ze serveru. Mám tam tenhle script: <script type="text/javascript"> alert("Jsi "+(navigator.onLine ? "online." : "offline.")); </script> , ale nefunguje to. Díky |
||
zacatecnik9 Profil |
#2 · Zasláno: 29. 3. 2009, 11:31:56
Takhle mi to funguje dobře:
<script type='text/javascript'> var xmlhttp=false; /*@cc_on @*/ /*@if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with old IE versions. // and security blocked creation of the objects. try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; } } @end @*/ if (!xmlhttp && typeof XMLHttpRequest!='undefined') { try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp=false; } } if (!xmlhttp && window.createRequest) { try { xmlhttp = window.createRequest(); } catch (e) { xmlhttp=false; } } xmlhttp.open("HEAD", "/faq/index.html",true); xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4) { var sra=xmlhttp.getAllResponseHeaders(); if(sra=='') {alert("nepripojeno");} else {alert("připojeno");} } } xmlhttp.send(null) </script> |
||
Časová prodleva: 15 let
|
0