views:

20

answers:

1

I have a photo gallery that use modal window to display photos. During modal windows initialisation I'm inserting rest of photo functionality (share button, comment, tags, etc). Everything works well except facebook share button. From documentation you have to include following html code:

<a name="fb_share">share</a> 
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" 
 type="text/javascript"></script>

It works perfectly for static pages, but not with the pages that created on the fly. Here is example of my javascript code (using jQuery)

//Insert share button
$.gallery.facebookLike.insertAfter($('#cboxContent #cboxLoadedContent'));

//Insert script element after share button
$('<script />', {
    src : 'http://static.ak.fbcdn.net/connect.php/js/FB.Share',
    type: 'text/javascript'
}).insertAfter($.gallery.facebookLike);

As result button inserted but script element is not initialised, after inspection in firebug this script appears in loaded script tab but not present on HTML tab. However if you click on the share link it sends you to facebook page and when you click BACK button in your browser the script gets initialised.

What am I doing wrong and what can be done about it?

+1  A: 

I'm just taking a guess here, but I believe the script has a function running on window onload event. Since the window is already loaded, the script isn't running.

Edit: Yes, it seems that the function FB.Share.stopScan is being run on window load. You should try manually calling that function.

Alex Nolan
all general scripts are initialised during onload event, facebook script is not loaded during this process, it should be triggered during image load. How ever I have tried to include it together with other scripts but it did not changed anything.
Nazariy