最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get a web browser to refresh automatically? - Stack Overflow

programmeradmin1浏览0评论

Say I want to run a simple Python script that is a web server. And I want to connect a browser to it that refreshes every N seconds, i.e. so the page is updated. How would I do that?

I assume the Python server script would generate some HTML that contains javascript that sleeps and forces a refresh? Or can the browser force a refresh?

Thanks in advance.

Say I want to run a simple Python script that is a web server. And I want to connect a browser to it that refreshes every N seconds, i.e. so the page is updated. How would I do that?

I assume the Python server script would generate some HTML that contains javascript that sleeps and forces a refresh? Or can the browser force a refresh?

Thanks in advance.

Share Improve this question asked Apr 2, 2009 at 10:36 NickNick 28k13 gold badges61 silver badges73 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 11
<meta http-equiv="refresh" content="5" />

That would reload the page after 5 seconds.

Refreshing the page is quite an old method and is generally a more expensive in terms of bandwidth than simply updating specific parts of your page. The solutions presented here already will do what you want, but you should also try looking into dynamic updates, using AJAX. It's not too hard to grasp. Basically rather than the browser refreshing the entire page, you can use AJAX to request only the data from the web-server that needs updating on the page.

There are plenty of tutorials on AJAX. If you need to support IE6, it can be just a tad more difficult, otherwise it is quite simple. In theory:

  1. Create an XMLHTTPRequest object.
  2. Tell it a URL that points to the data that needs updating on your page (it doesn't have to be XML).
  3. Give the object a function that can process the data when it is received.
  4. Tell the object to send the request to the server and retrieve the data.

Put the following under

<meta http-equiv="refresh" content="5" />

This will refresh the page after 5 seconds.

You could use the META-Tag for refresh or use javascript. But you have to take care that parameters in the URL are handled correctly and that you don't refresh POST actions if you don't intend to.

Use meta refresh tag. Though I'd be very surprised if a web page would suddenly update by itself. Some AJAXy stuff will be much more usable.

发布评论

评论列表(0)

  1. 暂无评论