简体   繁体   English

HTML自动刷新加载RSS源的DIV(文本)

[英]HTML Auto-Refresh a DIV loading an RSS Feed (text)

I want to make it so that the code automatically refreshes a DIV that displays an RSS Feed from last.fm to display the current music playing on my spotify. 我想这样做,以便代码自动刷新DIV,该DIV显示来自last.fm的RSS Feed,以显示我Spotify上正在播放的当前音乐。

This: 这个:

<script>
<div id="rss" style="height:25px;">
<iframe src="http://us1.rssfeedwidget.com/getrss.php?time=1400505489628&amp;x=http%3A%2F%2Fws.audioscrobbler.com%2F1.0%2Fuser%2Flukeassassin%2Frecenttracks.rss&amp;bc=333333&amp;bw=1&amp;bgc=transparent&amp;m=1&amp;it=false&amp;t=(default)&amp;tc=333333&amp;ts=15&amp;tb=transparent&amp;il=true&amp;lc=FF0000&amp;ls=28&amp;lb=false&amp;id=false&amp;dc=333333&amp;ds=14&amp;idt=false&amp;dtc=284F2D&amp;dts=12" border="0" hspace="0" vspace="0" frameborder="no" marginwidth="0" marginheight="0" align="center" style="border:0; padding:0; margin:0; width:600px; height:500px; text-align:center;" id="rssOutput"></iframe>
</div>
</div>
</script>

This is what it displays on the page: 这是它在页面上显示的内容:

图片

I would use javascript to fill the div with the information you want. 我将使用javascript将所需的信息填充到div中。 Then using an interval you can reload the contents every X seconds 然后使用间隔,您可以每X秒重新加载内容

Example: http://jsfiddle.net/T7cZU/3/ 示例: http//jsfiddle.net/T7cZU/3/

Javascript: Javascript:

$( document ).ready(function() {
    ReloadData()
    setInterval(function(){ReloadData()}, 1500);
});

function ReloadData(){
     $( "#result" ).load( "http://numbersapi.com/random/trivia", function() {});   
}

HTML: HTML:

<div id="result">
    Original content
</div>

or you could simply reload your iframe: 或者您可以简单地重新加载iframe:

setInterval(function(){
    document.getElementById('frame_id').contentWindow.location.reload();
}, 1500);

Updated fiddle with both methods of updating: http://jsfiddle.net/T7cZU/5/ 使用两种更新方法更新了提琴: http : //jsfiddle.net/T7cZU/5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM