Skip to content

Instantly share code, notes, and snippets.

@rocktronica
Created July 9, 2012 15:07
Show Gist options
  • Save rocktronica/3077065 to your computer and use it in GitHub Desktop.
Save rocktronica/3077065 to your computer and use it in GitHub Desktop.
refresh page w/ iframe
(function(win, doc, body){
var iCounter = 0, sUrl = doc.location.href, sTitle = doc.title || sUrl,
iMinutes = parseFloat(prompt("Seconds till refresh", "60"),10) || 60;
doc.head.innerHTML = body.innerHTML = '';
body.style.overflow = 'hidden';
var iframe = win.iframe = doc.createElement("iframe");
iframe.src = doc.location.href;
iframe.setAttribute('style',
'position:absolute;top:0;left:0;width:100%;height:100%;border:0'
);
body.appendChild(iframe);
iframe.onLoad = function() {
iCounter++;
doc.title = iCounter + ': ' + sTitle;
};
iframe.cycle = function() {
iframe.setAttribute('src', sUrl);
iframe.setAttribute('onLoad', 'iframe.onLoad()');
};
iframe.cycle();
setInterval(iframe.cycle, iMinutes*1000);
}(window, document, document.body));
@rocktronica
Copy link
Author

Big, hopefully obvious caveat: the page must not disallow iFrames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment