Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8700751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:14:25+00:00 2026-06-13T02:14:25+00:00

I am rather new to all things JavaScript so please bear with me :)

  • 0

I am rather new to all things JavaScript so please bear with me 🙂 I am trying to add ShareThis plugin to the title of FancyBox so that users can share a certain picture. It shows up nicely but nothing happens when I click on “share” buttons. Same plugin works on a regular page just fine, so I am guessing it’s conflicting scripts (plugin script inside the FancyBox script). Unfortunately, I don’t know JavaScript well enough to solve it on my own, but I really need this to work…

If anybody knows how to solve it, I will really appreciate it! Here is what I have so far code-wise:

Script for FancyBox (including showing elements in Fancybox title):

$(document).ready(function() {
$(".wrap").fancybox({
    closeClick  : false,
    nextEffect: 'fade',
    prevEffect: 'fade',
    beforeLoad: function() {
        var el, id = $(this.element).data('title-id');

        if (id) {
            el = $('#' + id);

            if (el.length) {
                this.title = el.html();
            }
        }
    },
    helpers : {
    title: {
        type: 'inside'
    }}
});

});

Here is what I need to show in the title:

<div id="title1" class="hidden">
<div class='share'>
<span class='st_facebook_hcount' displayText='Facebook'></span> 
<span class='st_twitter_hcount' displayText='Tweet'></span> 
<span class='st_pinterest_hcount' displayText='Pinterest'></span> 
<span class='st_email_hcount' displayText='Email'></span>
</div>
<p>Some description</p>
</div>

I included the ShareThis script from their website as well.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:14:30+00:00Added an answer on June 13, 2026 at 2:14 am

    Digging into the issue, it seems that the ShareThis buttons don’t really work on Ajax calls that return HTML, meaning the ShareThis button is defined in the synchronous data. Because that moving/copying the content from <div id="title1"> into fancybox’s title won’t work regardless that the ShareThis buttons’ html is perfectly rendered.

    The workaround is to build the buttons up dynamically while opening fancybox and prompt the ShareThis script to place those buttons again (inside the title) using their function stButtons.locateElements(); read mroe HERE. Of course, we have to use fancybox’s callbacks to sync the task.

    First, since what we want to share is specifically the content inside fancybox (I assume) and not the whole page, we need to create the function that builds the ShareThis buttons and pass the URL to share so

    function buildShareThis(url){
     var customShareThis  = "<div class='share'>"; // class for styling maybe
         customShareThis += "<span class='st_facebook_hcount' displayText='Facebook' st_url='"+url+"'></span> ";
         customShareThis += "<span class='st_twitter_hcount' displayText='Tweet' st_url='"+url+"'></span>";
         customShareThis += "<span class='st_pinterest_hcount' displayText='Pinterest' st_url='"+url+"' st_img='"+url+"' ></span>";
         customShareThis += "<span class='st_email_hcount' displayText='Email' st_url='"+url+"'></span>";
         customShareThis += "</div>";
         return customShareThis;
    }
    

    … the function above basically builds the same html structure as in the code you wanted to show in the title. Notice that I have added some ShareThis attributes (st_url and st_img in the case of pinterest … check ShareThis documentation about share properties and information)

    Then the html can be something like this

    <a href="images/01.jpg" class="fancybox" data-fancybox-group="gallery" data-caption="some description 01"><img src="images/01t.jpg" alt="thumb 01" /></a>
    <a href="images/07.jpg" class="fancybox" data-fancybox-group="gallery" data-caption="description two" ><img src="images/07t.jpg" alt="thumb 02" /></a>
    <a href="images/08.jpg" class="fancybox" data-fancybox-group="gallery" data-caption="third description 03" ><img src="images/08t.jpg" alt="thumb 03" /></a>
    

    Notice the data-* attributes set for each anchor so we can pass additional information to fancybox.

    Then, the fancybox callbacks :

    1) Use beforeShow to build the title calling buildShareThis(url) and add the caption from the data-caption attribute (if any) :

      beforeShow: function() {
         var caption =  $(this.element).data("caption") ? $(this.element).data("caption") : "";
         this.title = this.title ? this.title + buildShareThis(this.href) + caption : buildShareThis(this.href) + caption;
      }
    

    2) call ShareThis’ stButtons.locateElements() using afterShow :

      afterShow: function(){
         stButtons.locateElements();
      }
    

    …. that should do the trick.

    NOTE: You still need to bind the ShareThis scripts in your document like

    <script type="text/javascript">var switchTo5x=true;</script>
    <script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
    <script type="text/javascript">stLight.options({publisher: "ur-7957af2-87a7-2408-5269-db75628d3a14"});</script>
    

    (use your own publisher ID)

    This was tested using the latest fancybox version to date (v2.1.2), see WORKING DEMO HERE. Feel free to check the source code and modify it to fit your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please keep in mind that I'm rather new to how MVC, Json, jQuery, etc.
I'm rather new to C++ and I'm trying to understand the code over on
I'm rather new to jQuery and I'm trying to make a cool little menu
I have a rather deep hierarchy of objects that I'm trying to persist with
Rather new to php, so sorry if this seems stupid. I'm really copying a
Being rather new to ASP.MVC I'm looking for a solution to the following routing
I am rather new to the concepts of design patterns and I'm thinking of
I'm rather new to jQuery, so I really don't know if the following problem
I'm rather new to Backbone.js development, and have run into a bit of a
I'm rather new to working with multiple threads in a database (most of my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.