如何检查是否从上述URL加载图像

时间:2013-11-29 05:34:17

标签: javascript image amazon-web-services

var image = new Image();

image.onLoad = function() {
  alert("loaded");
}

image.onError = function() {
  alert("not loaded");
};

image.src ="https://s3.amazonaws.com/profileImages.mySample.com/spiderman.png" //dummy URL for reference only.

这是我的代码。 我从亚马逊服务中获取图像,问题是如果我收到一些错误,如:

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>ABCDEFGHIJ</RequestId>
<HostId>
AABCDEFGHIJKLMNOPQRST
</HostId>
</Error>

然后我的代码没有执行image.onError()。

如何检查网址中是否存在图片?

1 个答案:

答案 0 :(得分:0)

DEMO

var image = new Image();

image.onload = function() {
  alert("loaded");
}

image.onerror = function() {
  alert("not loaded");
};

image.src ="https://s3.amazonaws.com/profileImages.mySample.com/spiderman.png";