0

Hello I am trying to auto refresh this div tag. It contains an iframe that links to an outside url for a widget. I would like it to refresh every 30 seconds. Just curious how this can be done.

<div id="my-content">
<iframe src="https://discordapp.com/widget?id=*****************&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe></div>
</div>

<script>
$(document).ready( function() {
$('div.index-right').eq(0).append($('div#my-content'));
});
</script>

I am getting an uncaught exception error commented about below. This is for an external site that is linked in the iframe and there is no data being written locally to pull to update. The div simply needs to be refreshed.

Randy Bailey
  • 11
  • 1
  • 1
  • 6
  • AJAX post to PHP script every 30 seconds. PHP script returns data from a database/twitter widget/similar. – ScottMcGready Sep 07 '15 at 00:11
  • Did you look at any other answers [Refresh iFrame](http://stackoverflow.com/search?q=refresh+iframe)? – Dave Anderson Sep 07 '15 at 00:15
  • I did look for other answers all that I found were talking about refreshing the iframe for new data that was written to a file somewhere on the server. In this case the iframe is external and no data is written to the local server. – Randy Bailey Sep 07 '15 at 00:19

2 Answers2

1

Try this:

setInterval(function(){
    $('#my-content').load(location.href + " #my-content");
}, 30 * 1000);

This will only refresh the div with an id called my-content.

Beroza Paul
  • 2,047
  • 1
  • 16
  • 16
0

I think this should work, assuming you only have one iframe on the page.

setInterval(function(){
    $('iframe')[0].contentWindow.location.reload(true);
}, 30 * 1000);

to help with the security warnings you were getting, try the suggestions here: The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match

Community
  • 1
  • 1
0x736a64
  • 126
  • 6