开发者

If all images on page return an error redirect?

How can I make so if all the images on the page are 开发者_Go百科broken/don't exist javascript will redirect to another page?

I want to use this in an image gallery type script.


Give this script a try:

var imgCount = 0, imgErrorCount = 0;

function onImgError(increment) {
    if(increment) {
        imgErrorCount++;
    }
    if(imgCount > 0 && imgCount == imgErrorCount) {
        location = '/url-to-redirect';
    }
}
$(function(){
    imgCount = $('img').length;
    onImgError(false);
});

And for every img element:

<img src="..." onerror="onImgError(true);" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜