Hello,

I have this javascript function:

<script type="text/javascript">$(function() { YAHOO.MediaPlayer.addTracks(document.getElementById("ajazload"),1,false)});</scr*​ipt> <script type="text/javascript">

This function is loaded inside the <div id="main">, which is loaded via Ajax.

How can I prevent the javascript function to reload itself at every #main ajax page load ? I just want the javascript function loads at the first ajax load of the #main part of the page.

In fact, I want the Yahoo Media Player add tracks at the first load of the page, and not at every page load, because it's adding the same tracks at every page load...

Thanks !

This might make it work once only:

<script type="text/javascript">
if (yahooLoaded === undefined) {
  var yahooLoaded = 0;
}
if (yahooLoaded != 1) {
  YAHOO.MediaPlayer.addTracks(document.getElementById("ajazload"),1,false);
  yahooLoaded = 1; 
}
</scr​ipt> <script type="text/javascript">

But it may may it work once EVER (until the JS environment is reinitialized).

More context would help to provide a better solution.

Thank you very much for your help.

The code broke my ajax loading. However, I found a solution via cookies with Jquery, but I realized that my idea was wrong, because as you said, it loads once ever, so tracks are not playable after one reload (and I want to keep the button play next to every mp3 link).

Here is my test site, that is more talking that thousand words (and I'm not english well speaker...):
http://www.actupost.com

In fact, I'd like the Yahoo Media Player, in the left bottom, not add duplicate tracks at every load. However, I'd like to keep the play buttons on pages.

To make tests, just click several times on the first post and you'll see the playlist rise at every load. May you have solution to not make the playlist rise indefinitely with duplicate tracks ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.