I would like an iframe to refresh itself to the source path specified. What is the easiest way to do this inline with javascript?
thanks,
function refresh () { var iframe = document.getElementById ('iframe'); iframe.reload (true); } setTimeout ('refresh ()', 3000); Note, this will try to refresh the page every 3 seconds. Obviously, if the page takes a while to load, i.e. over 3 seconds then you wont see anything.
If you're also perhaps looking for a way of doing this without javascript enabled, and have access to modify the iframe HTML, then you could add this reload code to the <head> tag of the iframe HTML: Show activity on this post. You can use setInterval (function, milliseconds, param1, param2, ...)
The <iframe> allows web developers to embed one HTML page inside another. It’s so useful because they’re a part of HTML so you can use them almost anywhere — in website builders like Wix and Squarespace or in your next full-stack project.
However this is not viable if the frame's html is used as another stand alone page & you do not want to insert the 'meta refresh' inside it. The content must be between 30 and 50000 characters. … Download, Vote, Comment, Publish.
setInterval(function(){
document.getElementById("myframe").src+="";
},2500);
You can use setInterval(function, milliseconds, param1, param2, ...)
Something like this:
var frameRefreshInterval = setInterval(function() {
document.getElementById("myframe").src = document.getElementById("myframe").src
}, 2000);
The interval resets the iframe's src
attribute ever 2 seconds (2000 milliseconds)
Edit, to answer you comments:
This, along with any other code that manipulates the DOM, should be in a window.onload
event listener or similar like so:
<script type=text/javascript>
window.onload = function() {
var frameRefreshInterval = setInterval(function() {
document.getElementById("myframe").src = document.getElementById("myframe").src
}, 2000);
// any other code
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With