2013-08-03 120 views
2

使用setInterval調用在HTML正文中刷新網絡攝像頭圖像的函數時。這在Chrome中運行良好,但是,在Internet Explorer中,圖像不夠清爽。這是因爲緩存問題?Javascript setInterval無法在Internet Explorer中工作

<img id='camA' class='webcamStill' src='http://10.0.0.157/jpg/image.jpg' alt='Cam Image' /> 

window.setInterval(refreshWebcam, 3000); 

function refreshWebcam() 
{ 
    $('#camA').attr('src', 'http://10.0.0.157/jpg/image.jpg'); 
} 

回答

2

絕對。您將源設置爲已有內容,因此實際上並未發生變化,因此無需根據瀏覽器進行更新。

要cachebust,只是這樣做:

document.getElementById('camA').src = 
          "http://10.0.0.157/jpg/image.jpg?x="+new Date().getTime(); 

我以前Vanilla JS因爲原因。

+0

我想到了這一點,只是發佈後!將以答覆的形式向您致敬。我用'「?連接了url字符串+ Math.Random()':) – goingsideways

+1

時間更加獨特。 – CBIII

+1

我曾經使用'Math.random()',但總是有兩次獲得同樣事物的無限小的機會。使用當前時間保證兩次都不會得到同樣的結果(假設你沒有每秒重載數次) –

相關問題