Dynamically change image src using Jquery not working in IE and firefox

前端 未结 4 826
长情又很酷
长情又很酷 2021-01-12 09:06

I am implementing a captcha for a email. when click on linkEmail button email modal will open. there i have to set captcha image generated by a handler (Captcha

4条回答
  •  清歌不尽
    2021-01-12 09:35

    I had the same problem when trying to call re captcha button. After some searching, now function works fine in almost all the famous browsers(chrome,Firefox,IE,Edge,...):

    function recaptcha(theUrl) {
      $.get(theUrl, function(data, status){});
      document.getElementById("captcha-img").src = "";
      setTimeout(function(){
        document.getElementById("captcha-img").src = "captcha?"+new Date().getTime();
      }, 0);
    }
    

    'theUrl' is used to render new captcha image and can be ignored in your case. The most important point is generating new URL which forces FF and IE to rerender the image.

提交回复
热议问题