PDA

View Full Version : Sending variables out of the iframe



realwx
01-14-2007, 04:18 PM
Hey, I'm having a little problem with passing a function full of arrays out of an iframe to update the table boxes to a different color AND insert different text. Here is the main page (http://siriusuplink.com/whatson.php) and this is my code:

Main "Now Playing" JavaScript

var updated = new Array();

startTimer();
function startTimer() {
reloadframe();
setTimeout("startTimer();", 60000);
}

function reloadframe() {
document.getElementById("whatson").src="/whatson.php?js=2&t="+new Date().getTime();
}

function updateAll(streamdata) {
for(var i=0; i < streamdata.length; i++) {
var stream = streamdata[i];
var artist = "artist"+stream[0];
var artistD = document.getElementById(artist);
var song = "song"+stream[0];
var songD = document.getElementById(song);
var box = "box"+stream[0];
var boxD = document.getElementById(box);
var ch = "ch"+stream[0];
var chD = document.getElementById(ch);
if(songD.innerHTML == stream[2]) {
artistD.style.backgroundColor="#FFFFFF";
artistD.style.color="#000000";
songD.style.backgroundColor="#FFFFFF";
songD.style.color="#000000";
boxD.style.backgroundColor="#FFFFFF";
boxD.style.color="#000000";
chD.style.backgroundColor="#FFFFFF";
chD.style.color="#000000";
} else {
artistD.style.backgroundColor="#FAFAFA";
artistD.style.color="#FFFFFF";
songD.style.backgroundColor="#FAFAFA";
songD.style.color="#FFFFFF";
boxD.style.backgroundColor="#FAFAFA";
boxD.style.color="#FFFFFF";
chD.style.backgroundColor="#FAFAFA";
chD.style.color="#FFFFFF";
artistD.innerHTML = stream[1];
songD.innerHTML = stream[2];
}
}
}

HTML DIV & Table

<td class="trow1" valign="top" align="center" id="box1" width="16.666666666666666666666666666666667&#37;"><div id="ch1">1 - Hits 1</div><div id="artist1">Rob Thomas</div><div id="song1">Streetcorner Symphony</div></td>

iFrame placed before the BODY ending tag

<iframe src="/whatson.php?js=2" id="whatson" name="whatson" width="0" height="0" frameborder="0" style="display:none;"></iframe>

The function in the iframe that is being passed to parent

<SCRIPT LANGUAGE="JavaScript"><!--
var streamData = new Array(
new Array("1", "Rob Thomas", "Streetcorner Symphony"),
new Array("2", "Anna Nalick", "Breathe (2AM)"),
new Array("3", "Richard Marx", "Right Here Waiting"),
new Array("4", "Marty Balin", "Hearts"),
new Array("190","","")
);
parent.updateAll(streamData);
//--></SCRIPT>

Thanks!