Skip to content
Advertisement

Button onClick event does not work but works just fine when I display the Inspect mode in Chrome

The onClick event on the referesh button for the Captcha won’t work when I click it, but this button works well when I open the Inspect mode in Chrome and click it, refreshing the captcha as expected. Here is my HTML code :

JavaScript

Here is a screenshot of my UI :

enter image description here

What could be the problem in my case ?

Advertisement

Answer

The issue was due to Chrome and Firefox loading the captcha from Cache in the same tab, even if response header Cache-Control was set to no-cache. The solution was to add a random string parameter to the request, this forces Chrome to reload the captcha as it will see each time a new URL for the src attribute of the image. Something like this :

JavaScript

See this SO question for more details on this browser behaviour.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement