html - Javascript reloading iframe -
hi can me here have code works fine reloading iframe id cant seem work class reload more 1 iframe or failing more 1 iframe id.
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="pl" xml:lang="pl"> <head> <title>javascript iframe reload</title> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <script type="text/javascript"><!-- // set interval in milliseconds var reloadinterval = 3000; // run when document loaded function init() { settimeout('reload()',reloadinterval); } // reloads iframe, , triggers next reload interval function reload() { var iframe = document.getelementbyid('reloader'); if (!iframe) return false; iframe.src = iframe.src; settimeout('reload()',reloadinterval); } // load init() function when page loaded window.onload = init; --></script> </head> <body> <iframe id="reloader" width="500" height="400" src="http://www.google.com/"/> </body> </html>
you can use queryselectorall (compatible more browsers slower , different behavior) or getelementsbyclassname nodelist of elements can loop through.
var frames = document.queryselector(".myclass"); for(var i=0; i<frames.length; ++i) { reload(frames[i]); // you'll have modify function use parameter }
Comments
Post a Comment