我需要使用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時,我需要發送一個新的圖像請求。任何解決方法?