I have the code below that fetches images from a directory and displays in HTML. The images in this directory constantly change every second. It works somewhat on desktop browsers, but I cannot make it work on mobile browsers. It seems that it's always reading the cached images rather than reloading from the server. It can work by hitting ctrl+F5 on desktop browsers, but not on mobile browsers. Is there a way to hard refresh a mobile browser (chrome) via JavaScript?
<html>
<head>
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Expires" content="-1">
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
</head>
<body>
<img id="viewer" src="" width="100%"/>
<div id="info"> </div>
<button id="btnLeft" type="button">Left</button>
<button id="btnRight" type="button">Right</button>
<input type="button" value="Refresh page" onclick="location.reload(true);" />
<script>
$(function() {
var baseUrl = "./Cam01/";
var pictureIndex = 0;
var pictures = [];
function getFiles() {
$.ajax(baseUrl).success(function(data) {
pictures = [];
$(data).find("a[href]").each(function() {
var href = $(this).attr('href');
if (href.indexOf('.jpg') > 0 || href.indexOf('.png') > 0 || href.indexOf('.jpeg') > 0) {
pictures.push(href);
}
});
console.log(pictures.length + " pictures loaded!");
changePicture(0);
});
}
function changePicture(indexOffset) {
pictureIndex += indexOffset;
if (pictureIndex >= pictures.length) {
pictureIndex = 0;
} else if (pictureIndex < 0) {
pictureIndex = pictures.length - 1;
}
$('#viewer').attr('src', baseUrl + pictures[pictureIndex]);
$('#info').text((pictureIndex + 1) + "/" + pictures.length);
}
getFiles();
$('#btnLeft').click(function() {
var left = -1;
changePicture(left); return false;
});
$('#btnRight').click(function() {
var right = 1;
changePicture(right); return false;
});
$(document).keydown(function(e){
var left = -1, right = 1;
if (e.keyCode == 37) {
changePicture(left); return false;
} else if (e.keyCode == 39) {
changePicture(right); return false;
}
});
});
</script>
</body>
</html>