Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Facebook Share in a modal pop up window or standard pop up window

I'm trying to get my Facebook share button to open up in a modal window (a bit like lightbox opens images), but so far all I can get it to do is open in a brand new window, which I don't want.

I've noticed that Twitter opens in a small pop up window, which would be ideal if I can't get the Facebook Share window to open as a modal window. But again I can't seem to get the Facebook window to do this.

Any ideas on how I can do this?

like image 963
Hasan Avatar asked Apr 26 '14 10:04

Hasan


People also ask

What's the difference between modal window and pop up?

Modal windows are easier to notice because they're often styled in a way that matches the website theme. Popup windows use the operating system theme and controls, making one harder to distinguish from another. Modal windows also darken the background to cut the background noise.

How do you open a pop up window with modal?

My code to open a pop up: window. open("https://www.picpixa.com/wp-content/plugins/create-own-object/plugin-google-drive/index.php", "socialPopupWindow", "location=no,width=600,height=600,scrollbars=yes,top=100,left=700,resizable = no");

How do I open a pop up window?

The syntax to open a popup is: window. open(url, name, params) : url. An URL to load into the new window.

What is a modal window link?

03/08/2021. The Modal Text / HTML Link Element is another simple element, that allows you to add a text or html link to trigger a modal dialog, in conjunction with the Modal Element.


1 Answers

Try this:

HTML

<a class="fb-share" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fwww.manojyadav.co.in" target="_blank">
    Share on Facebook
</a>

jQuery

$(document).ready(function() {
    $('.fb-share').click(function(e) {
        e.preventDefault();
        window.open($(this).attr('href'), 'fbShareWindow', 'height=450, width=550, top=' + ($(window).height() / 2 - 275) + ', left=' + ($(window).width() / 2 - 225) + ', toolbar=0, location=0, menubar=0, directories=0, scrollbars=0');
        return false;
    });
});

Demo Link

Example Using Facebook JavaScript SDK

HTML

<a href="#" class="fb-share">Share on Facebook</a>
<div id="fb-root"></div>

JavaScript & jQuery

(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";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

window.fbAsyncInit = function() {
    FB.init({
        appId: '409742669131720',  // Change appId 409742669131720 with your Facebook Application ID
        status: true,
        xfbml: true,
        cookie: true
    });
};

$(document).ready(function() {
    $('.fb-share').click(function() {
        FB.ui({
            method: 'feed',
            name: 'Manoj Yadav',
            link: 'http://stackoverflow.com/users/2502457/manoj-yadav',
            picture: 'https://www.gravatar.com/avatar/119a8e2d668922c32083445b01189d67',
            description: 'Manoj Yadav from Mumbai, India'
        });
    });
});

To use the Facebook JavaScript SDK you will need to create a Facebook App and replace appId 409742669131720 with your appId

Demo Link

like image 172
Manoj Yadav Avatar answered Nov 15 '22 23:11

Manoj Yadav