开发者

Can't reload self-made captcha on the page using JS

开发者 https://www.devze.com 2023-04-08 19:06 出处:网络
<a href=\"javascript:void(0);\" onclick=\"document.getElementById(\"capchaimage\").src开发者_运维知识库=\"captcha.php\"><img id=\"captchaimage\" src=\"http://website.org/captcha.php\" border=
<a href="javascript:void(0);" onclick="document.getElementById("capchaimage").src开发者_运维知识库="captcha.php"><img id="captchaimage" src="http://website.org/captcha.php" border="0" width="70" height="20" alt="Captcha image"></a>

Captcha image successfully loads but it's not possible to reload it with the code above. What am I doing wrong?

Thanks in advance.


Your images are cached. Add a random string +(new Date).getTime() to at the query string after the image URL:

document.getElementById("capchaimage").src="captcha.php?"+ (new Date).getTime();


You are replacing image src with exactly the same string.

You can try to work around that by using some "fake" arguments:

http://website.org/captcha.php?fake=234342412341

That way the browser will be forced to reload. The argument needs to be different each time of course (random, or just counter)


Look carefully at your code:

<a href="javascript:void(0);" onclick="document.getElementById("capchaimage").src="captcha.php"><img id="captchaimage" src="http://website.org/captcha.php" border="0" width="70" height="20" alt="Captcha image"></a>
                                      ^                        ^

I'm surprised you are not getting JavaScript syntax errors. My advise is to move code to external functions to avoid the need of complex escaping.

0

精彩评论

暂无评论...
验证码 换一张
取 消