Forum Moderators: coopster
Thos other options are pretty cool, but they only appear to make the page look like it's working in real-time, the way php behaves never actually changes.
Anyway... my site IS frames so I'd like to see if it's possible to have say my news php file have it's text updated with the name of the artist/song playing ... the song being played of course on another php file in another frame.
So when a new song loads (each song has it's own page) the page sends the other php page the name of the artist and song playing. Can that be done without refreshing or reloading the page that the person may be reading at the moment?
I think everyone bad mouths frames for a reason, they're bad for users, search engines and programmers. Sure, they have their uses (I still use them for documentation where I have a javascript tree that cannot maintain state between page loads), but there are worthy replacements already.
You can do the song reload thing with XMLHttpRequest, just tell it to load a php file. Only thing is you are limited for browser compatibility.
When we see things like XUL and Apache Ant mature and enter mainstream programming frames will completely die.
Your frames will need to have a value in the `name` attribute so javascript can find it easily, then do something like this:
<script>
function changeSong(file)
{
// Where song is the name of the target frame;
parent.song.location.href = file;
}
</script>
Then in the song page's html:
<body onload="javascript:changeSong('song.php?song_id=1')"></body>
That will load the page song.php?song_id=1 into the song frame. I haven't tested it, but it's hopefully fairly straight forward... it should work (actually I'm not sure about the DOM reference parent.. might need to google the correct reference to the frame if it doesn't work).
Also, just some info on the XMLHttpRequest if you wanted to take another route without restricting your site to frames:
[developer.apple.com...]
<script>
addEvent(window, 'onload', function() {
changeSong();
});
function addEvent(obj, evType, fn){
if (obj.addEventListener){
obj.addEventListener(evType, fn, true);
return true;
} else if (obj.attachEvent){
var r = obj.attachEvent(evType, fn);
return r;
} else {
return false;
}
}
</script>
That should fire a function that calls changeSong() when the page loads... no need to fiddle with the body tag.
You may have to give up a little of your strict xhtml and go transitional...