/    Sign up×
Community /Pin to ProfileBookmark

Help on refresing Js Script

Hello? I have an online radio and i have a code from my service which tells the 5 last song that played. I want to make the code to refreshing evey minute. Here is the code, what i must add? (i’m a totaly noob)

[CODE]function cc_recenttracks_add(ncon,track,first){var ntrk=document.createElement(‘div’);ntrk.className=’cctrack’;var ncov=document.createElement(‘div’);ncov.className=’cccover’;var nimg=document.createElement(‘img’);nimg.src=track.image;nimg.align=’left’;nimg.width=50;nimg.height=43;ncov.appendChild(nimg);ntrk.appendChild(ncov);var ntit=document.createElement(‘div’);ntit.className=’cctitle’+(first?’ ccnowplaying’:”);ntit.innerHTML=track.title;ntrk.appendChild(ntit);var nart=document.createElement(‘div’);nart.className=’ccartist’;nart.innerHTML=track.artist;ntrk.appendChild(nart);if(track.url){var npri=document.createElement(‘div’);npri.innerHTML=”<a class=’ccbuy’ href='”+track.url+”‘>Buy this album</a>”
ntrk.appendChild(npri);}
ncon.appendChild(ntrk);}
function cc_recenttracks_get_callback(tracks,selfurl){var ccrte=document.getElementById(‘cc_recent_tracks’);if(!ccrte)return;ccrte.innerHTML=”;for(var i=0;i<tracks.length;i++){cc_recenttracks_add(ccrte,tracks[i],i==0);}}[/CODE]

thank you ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERFeb 03.2010 — I think you are looking for the setInterval() or setTimeout() functions.

Lots of examples here in forum search and on the web on how to use these.
Copy linkTweet thisAlerts:
@WestWebFeb 03.2010 — Yes I think you need to create another function that uses setInterval() to load those functions every minute. add this function right below the other two functions, [U]assuming[/U] they are in the <head> section of your site.
[CODE]
function loader()
{
// calls function when page loads
cc_recenttracks_add();
cc_recenttracks_get_callback();
// calls function again every 60000 milliseconds(1 minute)
setInterval(cc_recenttracks_add, 60000);
setInterval(cc_recenttracks_get_callback, 60000);
}
[/CODE]


Then You just need to change your HTML <body> tag to this:
[CODE]<body onload="loader()"[/CODE]

I hope this is right I am fairly new to the javasript myself.
×

Success!

Help @hambos spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...