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

  • Home
  • SEARCH
  • 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 3751766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:07:15+00:00 2026-05-19T09:07:15+00:00

Javascript and jQuery (Fancybox) question I’m using the Javascript function below for Twitter sharing

  • 0

Javascript and jQuery (Fancybox) question

I’m using the Javascript function below for Twitter sharing (as well as other services; the function code is simplified to just Twitter for this question) that grabs the to-be-shared page URL and title and it is invoked in the link with onclick. That results in the Twitter share page loading in a pop up browser window, i.e.<img src="/images/twitter_16.png" onclick="share.tw()" />

In order to be consistent with other design aspects of the site, what I’d like to be able to do is have the Twitter share page open not in a standard browser window but in a Fancybox (jQuery) window.

Fancybox can load an external page in an iFrame when the img or href link contains a class (in this case class="iframe" ) in the link and in the document ready function in the header.

Right now, of course, when I give the iframe class to the link that also has the onclick share.tw(), I get two popups: one browser window popup with the correct Twitter share page loaded, and a Fancybox jQuery popup that shows a site 404.

How can I change the function to use Fancybox to present the Twitter share page? Is that a correct way to approach it? Or is there a better way, such as implementing the share function in jQuery, too?

Thanks…

Javascript share function:

var share = {
   tw:function(title,url) {
        this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
    },
    share:function(tpl,title,url) {
        if(!url) url = encodeURIComponent(window.location);
        if(!title) title = encodeURIComponent(document.title);

        tpl = tpl.replace("##URL##",url);
        tpl = tpl.replace("##TITLE##",title);

        window.open(tpl,"sharewindow"+tpl.substr(6,15),"width=640,height=480");
    }
};

It is invoked, i.e.: <img src="/images/twitter_16.png" onclick="share.tw()" />

Fancybox function, invoked by adding class="iframe" in the img or href link

$(".iframe").fancybox({
'width' : '100%',
'height' : '100%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe'
});
  • 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-05-19T09:07:16+00:00Added an answer on May 19, 2026 at 9:07 am

    My approach would be to remove the fancybox initialization and trigger it directly from your share function:

    var share = {
       tw:function(title,url) {
            this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
        },
        share:function(tpl,title,url) {
            if(!url) url = encodeURIComponent(window.location);
            if(!title) title = encodeURIComponent(document.title);
    
            tpl = tpl.replace("##URL##",url);
            tpl = tpl.replace("##TITLE##",title);
    
    
            $.fancybox({
                            'href' : tpl,
                            'title' : title,
                            'width' : '100%',
                            'height' : '100%',
                            'autoScale' : false,
                            'transitionIn' : 'none',
                            'transitionOut' : 'none',
                            'type' : 'iframe'
                            });
    
            return false;
        }
    };
    

    I’m not sure my syntax is correct, but something like that should work for you.

    Another different attempt may be to use a dummy anchor, alter it’s attributes, and trigger click on it:

    jQuery(document).ready(function() {
    
            $("#dummyLink").fancybox({
                            'width' : '100%',
                            'height' : '100%',
                            'autoScale' : false,
                            'transitionIn' : 'none',
                            'transitionOut' : 'none',
                            'type' : 'iframe'
                            });
    
            return false;
        }
      };
    });
    var share = {
       tw:function(title,url) {
            this.share('http://twitter.com/home?status=##URL##+##TITLE##',title,url);
        },
        share:function(tpl,title,url) {
            if(!url) url = encodeURIComponent(window.location);
            if(!title) title = encodeURIComponent(document.title);
    
            tpl = tpl.replace("##URL##",url);
            tpl = tpl.replace("##TITLE##",title);
    
            $("#dummyLink").attr('href', tpl);
            $("#dummyLink").attr('title', title);
            $("#dummyLink").trigger('click');
            return false;
        }
    };
    

    HTML:

     <a href="#" title="" id="dummyLink" style="display:none;"></a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok. Here's my code: <script type=text/javascript language=javascript src=js/jquery-1.7.min.js></script> <script type=text/javascript src=js/fancybox/jquery.fancybox-1.3.4.pack.js></script> <link rel=stylesheet type=text/css
my file: <script type=text/javascript src={{ STATIC_URL }}js/jquery.fancybox-1.3.4.pack.js></script> <link rel=stylesheet href={{ STATIC_URL }}css/jquery.fancybox-1.3.4.css type=text/css media=screen
JavaScript/JQuery var arr=[]; $('.element').each(function(i) { arr.push({id:i,value:$(this).attr('data-value')}); }); $.get('/json.php?arr='+arr,function(result) { alert(result); }); PHP <?php $j
Javascript jQuery event handling If on event (for example 'click') bound one function for
I have this Javascript/JQuery code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script> <script type=text/javascript> name = $(#name).val(); alert(Name:
I have the following JavaScript/jQuery code that starts the listener that highlights the DOM
I'm using some javascript/jquery in an asp.net mvc view and I'm appending some html
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I am using jQuery Fancybox to display a number of Flash videos on a
I'm trying to do an image group with fancybox (I'm also using twitter bootstrap,

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.