Change dynamic link to sharebook sharebook

hi below is my code for dynamically changing facebook share button

        function f1() {
            $(function () {
                var id = location.href.replace(/.*pid=/, '');
                {"" + escape(id) + "&t=" + document.title, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600'); return false; }

<div onclick="f1()" id="sharenew" class="fb-share-button" data-href=""></div>


in said code sharebook sharebook accepts url, but I want to pass url with image id which gets C # value, so here my url will become " " but this is not consistent with facebook. so help me.


source to share

2 answers

given code works for me

        function FBShareOp(){
            var product_name = jQuery("#title").val();
            var description =   jQuery("#description").html();
            var share_image =   jQuery("#share_image").attr('src');
            var share_url   =   jQuery("#share_url").attr('href');
            var share_capt = jQuery("#share_capt").val();
            var id = location.href.replace(/.*pid=/, '');
                method: 'feed',
                name: product_name,
                link: id,
                picture: images,
                caption: share_capt,
                description: description

            }, function(response) {
                if(response && response.post_id){}


<a onclick="FBShareOp();" style="color: #fff; background-color: #435EAB; padding: 2px 7px 1px 7px; font-family: 'Helvetica Neue', Helvetica, Arial, 'lucida grande',tahoma,verdana,arial,sans-serif; font-size: 11px; text-decoration: none; border-radius: 2px; float: right; margin-top: 1px; margin-right: 45px;" href="#" title="Share" class="ymsb-fbshare-btn" data-target="popup" id="sharebutton">Share</a> &nbsp;




Use share FB.ui

for dynamic urls:

Basic example from docs:

  method: 'share',
  href: '',
}, function(response){});


You need to enable JavaScript SDK of course:

... and forget about the share button, just use your own button and call FB.ui on click.



All Articles