可能的重复项:
jQuery Ajax 等到所有图像都加载完毕
//var imgURL="http://xxxx.xxx:8084/xxx/largedynamicimagethattakestime
FB.api(
'/me/photos',
'post',
{
message:' coffee',
url: imgURL
},
function(response) {
if (!response || response.error) {
alert('Error occured'+response.error);
}
else {
//...........
}
}
);
我想仅在var imgURL
完成加载时启动此fb.api
调用。有什么方法可以让我可以在div
中加载此图像,并仅在图像完全加载时才调用fb.api
?也欢迎提供带有图像的按钮来发布此图像。
您需要侦听图像的 onload 事件:
var image = document.createElement("img");
image.onload = function() {
// Call API
};
image.src = "http://a57.foxnews.com/global.fncstatic.com/static/managed/img/Scitech/660/371/tardar-sauce-the-cat.jpg";
document.body.appendChild(image);