且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何测试是否存在互联网连接...

更新时间:2023-01-01 18:27:44

我认为此页面位于内部网或本地网络上 - 在这种情况下

你可以设置一个Body onLoad重定向到一个网页,另外设置一个

Javascript超时同时运行。如果互联网连接

存在,它会将浏览器重定向到它,如果它不存在那么

javascript超时会将用户重定向到''非互联网连接''

版本的页面?


不确定是否可能,但它的想法......


一个更好的方法是使用一个组件ping一个网址并等待

的回复。


Blabbering了一下并且想出来这里很响亮,但它可能会给你一个主意。


干杯,Ash

" ezmiller" <等************* @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
I presume this page resides on an intranet or local network - in which case
you could perhaps set a Body onLoad to redirect to a webpage, plus set a
Javascript timeout running at the same time. If the internet connection
exists it will redirect the browser to it, if it doesn''t exist then the
javascript timeout will redirect the user to a ''non internet connection''
version of the pages?

Not sure if thats even possible, but its an idea...

A better way to be to use a component to ping an internet address and wait
for a reply.

Blabbering a bit and thinking out loud here, but it may give you an idea.

Cheers, Ash
"ezmiller" <et*************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
有没有人知道如何使用javascript来测试是否存在
互联网连接?甚至可以吗?
Does anybody know how to use javascript to test whether or not an
internet connection exists? Is this possible even?



ezmiller于2005年12月15日在comp.lang.javascript中写道
ezmiller wrote on 15 dec 2005 in comp.lang.javascript:
有没有人知道如何使用javascript来测试是否存在
互联网连接?这有可能吗?


< img src =''http://myDomain.org/images/test1x1px.gif''

onerror =' 'alert(" no connection)''

onload =''alert(" CONNECTED")''
Does anybody know how to use javascript to test whether or not an
internet connection exists? Is this possible even?

<img src=''http://myDomain.org/images/test1x1px.gif''
onerror=''alert("no connection")''
onload=''alert("CONNECTED")''



-

Evertjan。

荷兰。

(用我的电子邮件地址替换所有带点的十字架)


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

>

ezmiller写道:
ezmiller wrote:
有谁知道如何使用javascript来测试是否存在
互联网连接?甚至可以吗?
Does anybody know how to use javascript to test whether or not an
internet connection exists? Is this possible even?




您可以使用XMLHttpRequest来查看您知道的某些资源是否可用于互联网。不是100%完美,但应该做到这一点。


< URL: http://jibbering.com/2002/4/httprequest.html >

-

Rob



You could use XMLHttpRequest to see if some resource that you know of on
the internet is available. Not 100% perfect, but should do the trick.

<URL: http://jibbering.com/2002/4/httprequest.html >
--
Rob