Re: How to trigger particular java script function?

From: Date: Thu, 04 Jul 2002 23:11:49 +0000
Subject: Re: How to trigger particular java script function?
Groups: php.general 
Request: Send a blank email to php-general+get-105540@lists.php.net to get a copy of this message
> >Hi friend, > I want to trigger one java script function ( time delay) every time. >How can I achieve this? > Here my questuion is: I want to play all song files from my database. > Here what I do is initially I display one button "PLAY" and then call >java script delay function and it has to come back to php script and >play next one again trigger to timedelay function etc... It would be infinitely easier to make a "play-list" streaming file. --------- file playlist.m3u ------------------- http://example.com/song1.mp3 http://example.com/song2.mp3 http://example.com/song3.mp3 ----------------------------------------------- Then just link to that and let people listen. If, however, you need to synchronize HTML output with the song's playing, I dunno how to do that... *MAYBE* you are on the right track for that, though I doubt it. I think there are custom software add-ons you'd develop/buy to do it right... Anyway, here's the fundamental thing you have to understand to proceed. PHP lives on your web-server. JavaScript lives on the surfer's browser desktop computer. The two of them can never, ever, really be running "at the same time". You can have PHP spew out JavaScript. You can have JavaScript make *ANOTHER* HTTP request to a different PHP page. Only problem is, every HTTP request is going to take time -- just like surfing to a new page. So it's gonna feel pretty slow and sluggish. Something like this might work: <?php if (!isset($song_number)){ $song_number = 1; } $query = "select title, filename from songs where song_number = $song_number"; $song = mysql_query($query) or error_log(mysql_error()); ?> <HTML> <HEAD> <SCRIPT LANGUAGE=JavaScript> function next_song(){ document.location = 'http://example.com/<?=$PHP_SELF;?>?song_number=<?=$song_number + 1?>'; } setTimeout('next_song', 2000); </SCRIPT> </HEAD> <BODY> <?=$title?><BR> <OBJECT SRC=<?=$filename> </BODY> </HTML> I can guarantee I have the OBJECT tag syntax wrong. And the rest ain't likely to be perfect either. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#105540) next »