954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Load a javascript function once per session on ajax website

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 , 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 !

job78
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

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.

Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
 

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 ?

job78
Newbie Poster
2 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: