1
我有一個實時鏈接到相機圖像,顯示鼠標懸停在鏈接上的時間。由於setInterval的原因,我不喜歡服務器日誌充滿每隔幾秒加載的圖像GET。clearInterval是否會導致重定向?
因此,我爲onInterval和clearInterval添加了onmouseover和onmouseout事件。這確實減少了服務器日誌中的事件數量。但是現在每次觸發事件時,我都會得到一個200和301的代碼。
在我添加鼠標事件之前,我只能從setInterval獲得200個代碼。我的問題是,有沒有辦法阻止301重定向,它是造成它的clearInterval?
var hold = null;
document.getElementById("test1").onmouseover = function() {
mouseOver()
};
document.getElementById("test1").onmouseout = function() {
mouseOut()
};
function mouseOver() {
var imgname = document.getElementById('imgfeed').src.split("?");
hold = setInterval(function() {
document.getElementById('imgfeed').src = imgname[0] + "?xrand=" + Math.floor((Math.random() * 1000) + 1);
}, 10000);
}
function mouseOut() {
clearInterval(hold);
}
.feedbtn:hover+.livefeed,
.feedbtn:active+.livefeed {
display: block;
}
.livefeed {
display: none;
}
<body>
<div id="test1">
<ul>
<li><a class="feedbtn">LINK</a>
<div class="livefeed">
<img src="link to camera image" alt="Feed" id="imgfeed" />
</div>
</li>
</ul>
</div>
</body>
響應代碼主要由「鏈接到相機圖像」指向的任何位置控制。也許這些託管服務器正在使用它作爲一種黑客方式,以確保您的瀏覽器不會緩存實時供稿。 'clearInterval'和'setInterval'的使用與圖像主機的響應標題無關。 –
爲什麼使用'setInterval'來獲取隨機圖像? – ewwink
setInterval用於刷新圖像。 – mcos