Something so simple is driving me nuts

Associate
Joined
28 Dec 2002
Posts
2,400
Location
Northern Ireland
Hi Guys,
I am trying to get an iframe to refresh every 30 seconds or so but I'm not getting anywhere.

This is the code I have so far and I'm hoping you guys can point out the problem which I have no doubt is very simple.

Code:
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>BNL Team Studio</title>
<style type="text/css">
body {
	background-color: #FFFFFF;
}
</style>
</head>
<body>
<script>
window.setInterval("reloadIFrame();", 30000);

function reloadIFrame() {
 document.frames["gdocs"].location.reload();
}
</script>

<img src="http://team.bnlproductions.co.uk/wp-content/uploads/10402900_731387893579539_2034696032886340019_n.jpg" alt="BNL Productions" />

<p><iframe width="1500" height="700" frameborder="0" name="gdocs" scrolling="no" src="https://docs.google.com/spreadsheet/pub?*******y4d-dE5PRlZBdWFydmJscW9xeXpvWVByZ1E&single=true&gid=4&output=html&widget=true"></iframe><br>

<iframe src="http://www.bbc.co.uk/radio/player/bbc_radio_one" width="380" height="150" frameborder="0" ></iframe>
</p>
</p>
  
</iframe></p>
</body>
</html>
 
Code:
<script>
function reloadIFrame() {
 document.frames["gdocs"].location.reload();
}
window.setInterval(reloadIFrame, 30000);
</script>
 
ace2109 - You'll be getting cross-origin exceptions. Check your browser's dev console. There's no easy way around that.

mrbell1984 - if you actually read the post you'll see neither of those examples are helpful. The first is useless because I doubt OP has the access to inject a meta tag onto Google's site, and the latter is the exact same code that is already there. In fact all you've done is change the name of the frame.
 
This is the error:
Code:
Refused to display 'https://docs.google[...]' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

edit: Actually, it may not be, just realised your link in OP has been truncated?
 
I think with google products you can change the query param output to "embed"

thus &output=html becomes &output=embed

Works for youtube links, anyway.
 
Rather than reloading the iframe, update its src:

Code:
<script>
window.setInterval("reloadIFrame();", 30000);

function reloadIFrame() {
var src = document.frames["gdocs"].src;
 document.frames["gdocs"].src = '';
document.frames["gdocs"].src = src;
}
</script>

This will avoid any cross-domain javascript issues.
 
why are people using "reloadIFrame();" and not just reloadIFrame as a parameter?! :/

Was wondering that. Putting it in a string is the equivalent of doing a javascript "eval" is it not? Can't remember why, but when I did a bit of js all the books said eval was evil :p
 
Back
Top Bottom