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

The below HTML/CSS/Javascript (jQuery) code displays the #makes select box. Selecting an option displays
New to javascript/jquery and having a hard time with using this or $(this) to
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I have some jQuery/JavaScript code that I want to run only when there is
I am using JavaScript and jQuery. My main file has My.js and Ajax. My.js
How do you detect which form input has focus using JavaScript or jQuery? From
I want to handle F1-F12 keys using JavaScript and jQuery. I am not sure
I'm looking for a good 10 minute introduction to Unobtrusive Javascript using JQuery. I'm
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
I am using jQuery Fancybox for a popup registration form here I would like

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.