本文介绍了使用javascript确定Web服务器是否正在响应。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试使用带有javascript的网页来检查网络服务器是否为响应。我在考虑使用2帧。 Frame1将拥有 站点,而Frame2将成为状态栏(不是真的需要)。这个 的网页将调用该网站的主页并在10秒内刷新。如果我 然后可以看到主页,那么网站就会启动,否则网站就会关闭。我有 我的代码示例如下。 我的问题是,是否可以检查第1帧中的主页( $ b $之后) b刷新)并查看页面是否出现。我要找的是 是HTTP错误还是找不到服务器或DNS错误页面。我想读取页面标题并将其与原始版本进行比较, 但我似乎无法在frame1中引用文档标题。或者 通过frame1中的文档文本进行解析,并查找关键字,例如 无法找到服务器...。另一个可能性是检查HTTP标头的。我通过许多新闻组和网站搜索,但是 仍然没有最终的解决方案。 任何帮助将不胜感激。 谢谢...... ***************************** ********************* **************** 示例代码 ********************************************* ***** **************** < html> < SCRIPT LANGUAGE =" JavaScript" > site =" http://www.timeanddate.com/counters/newyear.html" ;; delay = 10000; < / SCRIPT> < frameset rows =" *,25" border = 0 frameborder = 1 framespacing = 0 onLoad =" window.frames [0] .location = site; window.setInterval(''window.frames [0] .location = site'' ,延迟)"> < frame name =" TopFrame" scrolling = no> < frame name =" BottomFrame" scrolling = no> < / frameset> < / html> **** ********************************************** **** ************ 示例代码的变化 ****************** ******************************** **************** < html> < script language = javascript> site =" http://www.timeanddate.com /counters/newyear.html" ;; delay = 10000; 函数刷新() { window .frames [0] .location = site; //检查网站是否已启动的代码 } < / script> < frameset rows =" *,25" frameborder = 1 onLoad =" window.setInterval(''refresh()'',delay)"> < frame name =" TopFrame" scrolling = no> < frame name =" BottomFrame" scrolling = no> < / frameset> < / html>I am trying to use webpage with javascript to check if a web server isresponding. I was thinking of using 2 frames. Frame1 will have thesite, and the Frame2 will be a status bar (not really needed). Thiswebpage will call the site''s homepage and refresh in 10 seconds. If Ican see the homepage then, the site is up, else site is down. I havean example of my code below.My question, is it possible to check the homepage in frame1 (afterrefreshed) and see if the page comes up. What I would be looking foris HTTP Errors or "Cannot find server or DNS Error" pages. I wasthinking of reading the page title and compare it with the original,but I cannot seem to reference the document title within frame1. Orparse thru the document text in frame1 and look for keywords like"Cannot find server...". Also another posssibility could be to checkthe HTTP header. I have search thru many newsgroups and websites, butstill haven''t got a final solution.Any help would be greatly appreciated.Thanks...************************************************** ****************Sample Code************************************************** ****************<html><SCRIPT LANGUAGE="JavaScript">site="http://www.timeanddate.com/counters/newyear.html";delay=10000;</SCRIPT><frameset rows="*,25" border=0 frameborder=1 framespacing=0onLoad="window.frames[0].location=site;window.setInterval(''window.frames[0].location=site'',delay)"><frame name="TopFrame" scrolling=no><frame name="BottomFrame" scrolling=no></frameset></html>************************************************** ****************Variation of Sample Code************************************************** ****************<html><script language=javascript>site="http://www.timeanddate.com/counters/newyear.html";delay=10000;function refresh(){window.frames[0].location=site;//code to check if site is up}</script><frameset rows="*,25" frameborder=1onLoad="window.setInterval(''refresh()'',delay)"><frame name="TopFrame" scrolling=no><frame name="BottomFrame" scrolling=no></frameset></html>推荐答案 希望你能用它。 欢迎提出改进建议。 / L - Lasse Reichstein Nielsen - lr*@hotpop.com DHTML死亡色彩:< URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html> ''没有判断力的信仰只会降低精神神圣。''Hope you can use it.Suggestions for improvement are welcome./L--Lasse Reichstein Nielsen - lr*@hotpop.comDHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>''Faith without judgement merely degrades the spirit divine.'' 当然时间戳很简单并保证不会发生冲突,除非用户改变了他们的时钟,这是一般不太可能。 吉姆。 - comp.lang.javascript常见问题 - http://jibbering.com/faq/Surely a timestamp would be simple and guarantee non collision unlessthe user changed their clock, something that is generally unlikely.Jim.--comp.lang.javascript FAQ - http://jibbering.com/faq/ 这篇关于使用javascript确定Web服务器是否正在响应。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-01 17:26