telexper
telexper

Reputation: 2441

How to set interval for refresh of iframe on click only

I want to set a timer for the reload of my iframe, but the timer will only start when the user clicks the button. Is there any way to do it? My code refreshes the iframe every 3 seconds instead of onclick.

code:

function reloadIFrame() {
     setInterval(function(){window.frames['frame'].location.reload();},3000);
}

button:

 <input type="submit" value="Save" onclick="reloadIFrame()"/>

I want the iframe to refresh after 3 seconds when the user clicks the button.

Upvotes: 0

Views: 1655

Answers (2)

theintersect
theintersect

Reputation: 758

Seems that you just want to put a delay on the action. What you are doing is using the setInterval which will run the function every three seconds. You are looking to set a delay, you should use, in that case you should use the setTimeout function.

 setTimeout(function(){window.frames['frame'].location.reload();},3000)

Upvotes: 0

xdazz
xdazz

Reputation: 160873

I think you need setTimeout instead of setInterval

function reloadIFrame() {
   setTimeout(function(){window.frames['frame'].location.reload();},3000);
}

Upvotes: 1

Related Questions