0

I've got a script which displays an alert showing whether an image has been located or not, but I'm looking to prevent a false positive from the image being cached by the browser.

Usually I add something like "http://192.168.8.1/images/ping2.jpg"+"?rand="+randomNum; to add a random number but I'm finding this is not working with this implementation.

<script> function pingImage(URL) {
    var tester=new Image();
    tester.onload=imageFound;
    tester.onerror=imageNotFound;
    tester.src=URL;
}

function imageFound() {
    alert('That image is found and loaded');
}

function imageNotFound() {
    alert('That image was not found.');
}

pingImage("http://192.168.8.1/images/ping2.jpg");

</script>
  • The cachebuster URL parameter definitely should work. The cache has to include the URL parameters. – Barmar Jun 26 '17 at 16:34
  • Try [this related answer](https://stackoverflow.com/a/333657/266535). Does that work for you? – styfle Jun 26 '17 at 17:16

0 Answers0