Javascript fixes the SRC problem with the IMG tag

  • 2020-03-30 02:29:04
  • OfStack

1. When a button is clicked, change the image in the image field
<img id="randimg" src="/servlet/CreateValidateNum" width="60" height="20" /> 
<span style="cursor:hand" onclick="reflush();return false;"> Can't see </span> 
function reflush() 

2. Show
"The servlet/CreateValidateNum" is written by JAVA servlets. The servlet prints out pictures

3. Problems arise
The image is changed normally under IE6, but does not refresh under IE7 and Firefox

4. Situation analysis
If the new image does not have the same address as the old one, the effect will come out. That is: the picture has changed.
But things like captcha. The addresses of the old and new pictures are the same.
In view of the above, it is possible that the browser automatically reads the cache because the image address is the same.

5. Solutions
Change javascript to this:
Document. The getElementById (randimg). SRC = "/ servlet/CreateValidateNum?" + Math. The random ();
That is: each access address is different, because a random number. So problem solving

Related articles: