Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

JavaScript Google Presentation

Hi,

I was wondering if anyone can help.

I have embedded a Google Presentation into a website via an iFrame. However I also need some JavaScript to refresh the iFrame every 5 minutes as other user will be adding slides and without a refresh the new slides do not show.

I have searched high and low without any luck. I was given the code below but cannot get it to work, can anyone help?

<script>

function refresh() {

document.getElementById("iframeID").src=

"https://docs.google.com/presentation/d/1opxfEOEODaO6VgH12blw-xly1m_Lnt1W-yHfozhVV0k/embed?start=false&loop=false&delayms=3000";

}

setInterval(refresh, 5000);

</script>

<iframe src="https://docs.google.com/presentation/d/1opxfEOEODaO6VgH12blw-xly1m_Lnt1W-yHfozhVV0k/embed?start=false&loop=false&delayms=3000" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>

1 Answer

It looks like the refresh function gets the element, but never does anything to reload it try something like this:

```function refresh(){ document.getElementById('some_frame_id').contentWindow.location.reload(); }

setInterval(refresh, 1000*60*5);```

There are a couple of good StackOverflow thread on the subject, so they may also be a good reference: http://stackoverflow.com/questions/86428/whats-the-best-way-to-reload-an-iframe-using-javascript

Hi Jeff,

Thank you for the code above. I can now get the iFrame to refresh, however when it does refresh it re-loads the editors panel(view) on the web site and not the slide show presentation.

I am a complete novice, so if anyone has achieved this and has clear examples I can follow, that would be great.

Here is the current code I have been trying to using:

    function refresh(){ document.getElementById('test').contentWindow.location.reload(); }
setInterval(refresh, 1000*60*5)

```<iframe id='test' src="https://docs.google.com/presentation/d/1opxfEOEODaO6VgH12blw-xly1m_Lnt1W-yHfozhVV0k/embed?start=true&loop=true&delayms=3000" frameborder="0" width="960" height="569" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true"></iframe>```