浏览器刷新页面的三种方式
2006-09-25 09:49
337 查看
浏览器(Browser)刷新页面的三种方式
1:通过直接写HTML TAG刷新,即所谓的"Client pull"方式
<html>
<title>EE4000 System Info</title>
<meta http-equiv="Refresh" content="3">
<link rel="stylesheet" href="../../App_comm/html/main.css" type="text/css">
……………
</html>
Browser 将会每隔3秒刷新一次此页面.
2:通过Refresh响应头通知Browser 刷新
Browser发出请求,Server发出响应,如果在响应头中加入Refresh头(格式如下),Browser就会根据Refresh中的值
再次发出请求(如果值为0则不发).比如Server发出以下响应报文,将通知Browser 3秒后刷新一次(仅一次,如要再次刷新,仍然需要在响应报文中加入Refresh响应头).
HTTP/1.0 200
Content-type: text/html
Refresh:3; URL=http://192.168.11.21/App/html/snmp.html
我查找了HTTP1.0,并未发现Refresh的定义,Refres头可能属于extension-header之列.由于Refresh不是标准
头,因此不能保证所有Browser都识别它进而刷新.
3:通过Content-Type响应头刷新,这也是通常所谓的"Server push"方式,不过IE目前并不支持这种用法
Server以如下方式回响应
先发:
HTTP/1.0 200
Content-Type:multipart/x-mixed-replace;boundary=NEXT
--NEXT
Content-type: text/html
First data(或图片)
等待一段时间之后再发(注意此时不发"HTTP/1.0 200"等Head了):
--NEXT
Content-type: text/html
Second data
...
等待一段时间之后再发结束报文:
--NEXT
last data
--NEXT--
在以上Content-Type:multipart/x-mixed-replace;boundary=NEXT头中,x-mixed-replace表示通知Browser收到数
据后在显示时要覆盖前面收到的数据,NEXT为边界符.这种Server push机制的特点是:Server发送完第一部分
response之后并不关闭socket,一直报持保持open(这样会导致Server端打开较多的TCP/IP port),如果Server每次
传送的是一张图片,只要间隔时间足够短的话则可形成动画效果.Server push机制对于开发web 即时通信工具(IM)
是比较关键的.
为了便于理解,以下为Server端产生响应报文的代码:
echo "HTTP/1.0 200"
echo "Content-type: multipart/x-mixed-replace;boundary=NEXT"
echo ""
echo "--NEXT"
while true
do
#
# Send the next part, followed by a boundary string
# Then sleep five seconds before repeating
#
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo "<title>Processes On This Server</title>"
echo "</head>"
echo "<body>"
echo "<h3> Processes On This Server</h3>"
echo "Date:"
date
echo "<p>"
echo "<pre>"
ps -el
echo "</pre>"
echo "</body>"
echo "</html>"
echo "--NEXT"
sleep 5
done
1:通过直接写HTML TAG刷新,即所谓的"Client pull"方式
<html>
<title>EE4000 System Info</title>
<meta http-equiv="Refresh" content="3">
<link rel="stylesheet" href="../../App_comm/html/main.css" type="text/css">
……………
</html>
Browser 将会每隔3秒刷新一次此页面.
2:通过Refresh响应头通知Browser 刷新
Browser发出请求,Server发出响应,如果在响应头中加入Refresh头(格式如下),Browser就会根据Refresh中的值
再次发出请求(如果值为0则不发).比如Server发出以下响应报文,将通知Browser 3秒后刷新一次(仅一次,如要再次刷新,仍然需要在响应报文中加入Refresh响应头).
HTTP/1.0 200
Content-type: text/html
Refresh:3; URL=http://192.168.11.21/App/html/snmp.html
我查找了HTTP1.0,并未发现Refresh的定义,Refres头可能属于extension-header之列.由于Refresh不是标准
头,因此不能保证所有Browser都识别它进而刷新.
3:通过Content-Type响应头刷新,这也是通常所谓的"Server push"方式,不过IE目前并不支持这种用法
Server以如下方式回响应
先发:
HTTP/1.0 200
Content-Type:multipart/x-mixed-replace;boundary=NEXT
--NEXT
Content-type: text/html
First data(或图片)
等待一段时间之后再发(注意此时不发"HTTP/1.0 200"等Head了):
--NEXT
Content-type: text/html
Second data
...
等待一段时间之后再发结束报文:
--NEXT
last data
--NEXT--
在以上Content-Type:multipart/x-mixed-replace;boundary=NEXT头中,x-mixed-replace表示通知Browser收到数
据后在显示时要覆盖前面收到的数据,NEXT为边界符.这种Server push机制的特点是:Server发送完第一部分
response之后并不关闭socket,一直报持保持open(这样会导致Server端打开较多的TCP/IP port),如果Server每次
传送的是一张图片,只要间隔时间足够短的话则可形成动画效果.Server push机制对于开发web 即时通信工具(IM)
是比较关键的.
为了便于理解,以下为Server端产生响应报文的代码:
echo "HTTP/1.0 200"
echo "Content-type: multipart/x-mixed-replace;boundary=NEXT"
echo ""
echo "--NEXT"
while true
do
#
# Send the next part, followed by a boundary string
# Then sleep five seconds before repeating
#
echo "Content-type: text/html"
echo ""
echo "<html>"
echo "<head>"
echo "<title>Processes On This Server</title>"
echo "</head>"
echo "<body>"
echo "<h3> Processes On This Server</h3>"
echo "Date:"
date
echo "<p>"
echo "<pre>"
ps -el
echo "</pre>"
echo "</body>"
echo "</html>"
echo "--NEXT"
sleep 5
done
相关文章推荐
- 浏览器(Browser)刷新页面的三种方式
- 浏览器刷新页面的三种方式
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- 跨浏览器通用的页面刷新方式
- 浏览器三种刷新方式采取的不同缓存机制
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- 浏览器刷新的三种方式
- 浏览器三种刷新方式对浏览器缓存的影响
- 浏览器三种刷新方式所采取的缓存机制
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- ASP.NET后台代码方式识别页面“按钮点击”和浏览器F5“刷新”事件
- 前台页面自动刷新三种实现方式
- 浏览器自动刷新网上指定页面的两种方式(我知道的)
- 浏览器三种刷新方式的缓存机制-----单点登录SSO的实现原理---PHP版单点登陆实现方案
- 浏览器三种刷新方式所采取的缓存机制
- 浏览器返回按钮不会刷新页面解决方案---使用情景:点击浏览器左上角的后退按钮,页面需要刷新的情况
- iframe实现无刷新上传文件并在当前页面返回数据php处理方式
- 使用服务端事件委托机制来防止页面重复提交数据或客户端浏览器使用(F5)刷新提交数据
- Jquery easyui datagrid在IE 9浏览器下,删除数据后,页面刷新数据仍显示的问题。
- HTML页面实现自动刷新的2种方式