我需要使用JavaScript轮询图像,并且需要在图像位于其位置时执行操作。这是我为此任务编写的代码。通过javascript图像轮询
/*----Image handling script starts here----*/
var beacon = new Image();
beacon.onload = function() {
console.log('Image found');
console.log(this.width,this.height);
window.clearInterval(timer);
};
beacon.onerror = function(){
console.log('Image not found');
}
var timer = window.setInterval(function(){
console.log('sending the request again');
beacon.src = "http://www.google.co.in/logos/2010/lennon10-hp.gif";
},2000);
/*----Image handling script ends here----*/
问题是,一个GET请求后,响应被缓存,并要求不要让每次送我设置SRC。如果您检查NET选项卡,它仅在第一个src集中发送请求并缓存响应。
每当我的代码设置src时,我需要发送一个新的图像请求。任何解决方法?