1

I'm working on a wordpress editor where I need to be able to refresh images without having to reload the page. However, I'm not getting the plot as I'm not really a javascript master :(

I'm running this, but in the console log, all I get is: "Uncaught ReferenceError: updateImage is not defined". What am I doing wrong?

<script>

    var newImage = new Image();
    newImage.src = "http://2famous.tv/wp-content/uploads/2013/07/Dubai-Sky-scrapers_thumb_one.jpg";

    function updateImage() {
    if(newImage.complete) {
        document.getElementById("thumb1").src = newImage.src;
        newImage = new Image();
        newImage.src = "http://2famous.tv/wp-content/uploads/2013/07/Dubai-Sky-scrapers_thumb_one.jpg?" + new Date().getTime();

    }

        setTimeout(updateImage, 1000);
    };


</script>

<img id="thumb1" src="image.jpg" onload="updateImage();">
2famous.TV
  • 460
  • 1
  • 6
  • 23

1 Answers1

1

When the <img> is loading, the <script> is not loaded yet. So, the updateImage() method doesn't exists. Try to use jquery, there you could do it easily with the ready event.

eKek0
  • 23,005
  • 25
  • 91
  • 119