1

I have a problem with executing javascript with .load function in jquery. In my main js file I have something like it:

var dt = new Date();
$(".pp_social").load("trackingCode.html?"+ dt.getTime());

and in trackingCode.html

<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="www.blah.com" data-send="true" data-width="450"   data-show-faces="true"></div>


When I run it for the first time is fine. Then any next time I invoke it, it omits javascript part. Any ideas what coluld be wrong and why?


Cheers, Bartek

1 Answer 1

4

Well, your script creates an element and gives it the id value "facebook-jssdk". There's a line at the top:

if (d.getElementById(id)) { return; }

Thus, once it's created the element, it'll never do anything again.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok. Understand. At the moment it is like button for a each photo in a gallery. What is the best method to make that part unique and working?
Well I'm not sure why you'd need to re-import the code over and over again.
Cause I didn't know how to put multiple 'I like' buttons on one site (gallery). I've already found below code and it works fine:
Cause I didn't know how to put multiple 'I like' buttons on one site (gallery). I've already found a method here: (raahede.com/blog/2010/10/12/…) and it works fine. Thanks 4help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.