Skip to content

Instantly share code, notes, and snippets.

@aliqorbani
Last active June 1, 2024 10:24
Show Gist options
  • Save aliqorbani/7a44d078bd60f6019adebf4b661c14c1 to your computer and use it in GitHub Desktop.
Save aliqorbani/7a44d078bd60f6019adebf4b661c14c1 to your computer and use it in GitHub Desktop.
reload a custom url using iframe and js with loop
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Reloading iframe using js</title>
</head>
<body>
<iframe marginwidth="0" id="inserts" marginheight="0" scrolling="no" src="" frameborder="0" style="height: 2em;padding: 0;margin: 0;width: 100%;"></iframe>
<p id="times"></p>
<script>
var times_reloaded = 0;
var iframe_src = 'URL_HERE';
var loop_timeout = 3000;
window.setInterval("reloadIFrame();", loop_timeout);
function reloadIFrame() {
document.getElementById("inserts").src= iframe_src;
times_reloaded++;
document.title = times_reloaded + ' times reloaded';
document.getElementById('times').innerHTML = 'times reloaded : ' + times_reloaded;
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment