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();">
5
  • newImage.complete <--- ".complete" is not JavaScript. Commented Jul 18, 2013 at 17:25
  • Not sure... have it from this thread: stackoverflow.com/questions/1077041/… Commented Jul 18, 2013 at 17:27
  • This code works as written here. Usually when I get that error there is a javascript syntax error somewhere on the page, usually a close bracket } or something. Do you have other javascript code on the page? Commented Jul 18, 2013 at 17:44
  • @Diodeus - yes it is. developer.mozilla.org/en-US/docs/Web/API/… Commented Jul 18, 2013 at 17:46
  • Wow, never seen that before. Thanks. Commented Jul 18, 2013 at 17:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I think that my best option here is to use unique filenames for each adjustment...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.