最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Way to force image to reload from server - Stack Overflow

programmeradmin4浏览0评论

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?

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?

Share Improve this question edited Jan 24, 2013 at 3:57 jfriend00 709k104 gold badges1k silver badges1k bronze badges asked Jan 24, 2013 at 3:48 GWRGWR 1,9885 gold badges31 silver badges47 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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

oImgElement.src = oImgElement.src + '?' + Math.random();
发布评论

评论列表(0)

  1. 暂无评论