GWR
GWR

Reputation: 2008

Way to force image to reload from server

I've seen all of the other posts on similar issues with setAttribute() in IE, but can't seem to get any of the workarounds to, er, work (specifically for the src attribute of an img element.

The example:

function reloadCaptcha(sImgElementId) {
    var oImgElement = document.getElementById(sImgElementId);
    oImgElement.setAttribute('src', oImgElement.src);
    return false;
} 

And the img element:

<img id="nlc" name="nlc" src="/inc_captcha.asp" onClick="javascript:reloadCaptcha('nlc'); return false;" />

It just reloads the src. Works like a charm in Chrome and FF. Nada in IE.

How can I make this work in IE?

Upvotes: 1

Views: 5252

Answers (1)

dfsq
dfsq

Reputation: 193261

I'm pretty sure it will reliably reload your captcha image:

oImgElement.src = oImgElement.src + '?' + Math.random();

Upvotes: 7

Related Questions