开发者

using jQuery to modify DOM element after page content has fully loaded

I apologise in advance if my question seems a bit misleading, but I'm trying to wrap my head around this one.

I have a flash-based MP3 player (http://blog.lacymorrow.com/projects/xspf-jukebox) that exposes a Javascript API that is really handy for my situation. I am using jQuery and swfObject to embed the Flash player and that works well.

Now the player has auto-resume and auto-play functions that cause it to immediately start playing when the page is loaded, which is great. However, what I am trying to do is STOP the player when a certain page is browsed to. For instance, when I browse to contact.html, I want the player to stop playing any music. I had thought that the following would work:

$(function($) {
  window.document.myJukebox.stopTrack();
}); 

I then remembered that everything inside $(document).ready() or $(function($) {}) will execute as soon as the DOM is loaded BUT before all page contents are loaded. What I need to do is ensure that the above script runs without any user intervention once the entire page is fully loaded --> this is what I am stuck with and need your help with, please. If I have the following hyperlink on the page:

<a id="player-sto开发者_Python百科p" href="javascript:window.document.myJukebox.stopTrack();">Click to Stop</a>

and click it, then the player does stop, so its clear to me that I need to have something that runs automatically without the user having to click on a STOP button. I have tried running this in a script at the bottom of the page with no luck.

Thank you!


Try using setTimeout to schedule execution of your stop function later. If you have some sort of property on myJukebox that tells if player is playing or not, you can use setInterval and make it clear itself when it actually stops the player.

Also, it is worth investigating if player has some sort of startPlaying event and stop it after it fired the startPlaying event.


I'm guessing the first one does not work because the DOM is actually ready, but the Flash content is not at that time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜