简体   繁体   中英

Refresh browser when div contents changed

within the <div> I embedded an <img> , sometimes I have the problem that the browser didn't reload when new img came. So I refresh the browser within a specific time intervall. But how can I force the browser automatically refresh, when <div> contents changed? I use Internet Explorer and don't want to use Ajax or Jquery. It would be great if we find a solution in Javascript or Html only.

<body onload="JavaScript:AutoRefresh(5000);">

then in <script> section I set to window.location.reload(1)

For this solution is not user-friendly.

Hope you find a better solution.

尝试改变形象?

<img src="./img.src" onchange="javascript:window.location.reload();"

Looks like this means you are changing the image on the webserver, and want the browser to automatically reload. But the problem is that the browser would not know when the image has changed, unless you reload.

You can use a http request to poll the server.

It is not clear what way the image is updated, but I'd do this:

  • any time the image is changed put the hash or last update timestamp under a URL on my server
  • use XMLHttpRequest (eg: https://stackoverflow.com/a/4033310/ ) to poll the hash/timestamp from the server every x seconds or minutes
  • compare the received data with the last known value
  • reload the page if it is different

This way the page would only reload, when the image has changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM