0

可能重复:
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 {
            //...........
        }
    }
);

我只想在完成加载后启动此fb.api调用。var imgURL有什么方法可以让我在 a 中加载此图像并仅在图像完全加载时div调用?fb.api也欢迎提供带有图像的按钮来发布此图像。

4

1 回答 1

1

您需要监听图像的 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);
于 2012-12-11T15:43:47.450 回答