Javascript: Run setInterval only once

Homie picture Homie · Jan 24, 2013 · Viewed 18.5k times · Source

Possible Duplicate:
setInterval - How to fire only once?

I would like to run the following code only once, so after 2 seconds it will change the iframe's src, but won't try to do it again and again.

<script type="text/javascript">
    setInterval(function () {document.getElementById('iframe').src = "http://www.y.com";}, 2000);
    </script>

Answer

SLaks picture SLaks · Jan 24, 2013

You're looking for setTimeout(), which does exactly that.