Thursday, August 15, 2013

Share Contents to Social Network sites in SharePoint

Sharing the URL of the Page and Contents through Social Network will increases the exposure of the Site. If you want to increase the exposure and get attention for your public site, you can simply use some of the API’s provided by the Social sites. We just need to call the URL with Passing your Page informations.

Facebook:
Redirect the User to below URL by replacing the below bolded content with appropriate Content.
'http://www.facebook.com/sharer.php?s=100&p[title]= ' + title + '&p[summary]=' + desc + '&p[url]=' + linkUrl + '&p[images][0]=', 'sharer', 'toolbar=0,status=0'

Twitter:
Redirect the User to below URL by replacing the below bolded content with appropriate Content.
'http://twitter.com/home?status=Title ' + desc + '  Page Url:' + linkUrl + '', 'twitter', 'toolbar=0,status=0'
 

Google+:
Redirect the User to below URL by replacing the below bolded content with appropriate Content.
"https://plus.google.com/share?url=" + escape(linkUrl);

 
 
<script type="text/javascript">

/*We have used Field Controls to store Page Title and Page Description and added the Field Controls in the Pagelayout, So that Page Title and description of each Page available as a Control*/
function shareData(sitename) {
    var pgTitle = document.getElementById('pageTitle');
    if (pgTitle != null && pgTitle != undefined && pgTitle != '') {
        if (document.all) {
            title = pgTitle.innerText;
        } else {
            title = pgTitle.textContent;
        }
    }
 
    var pgDesc = document.getElementById('pageDescription');
    if (pgDesc != null && pgDesc != undefined && pgDesc != '') {
        if (document.all) {
            desc = pgDesc.innerText;
        } else {
            desc = pgDesc.textContent;
        }
    }
    var linkUrl = window.location.href;
    var body = desc;
 
    if (sitename == 'facebook') {
        u = location.href;
        t = title;
 
        window.open('http://www.facebook.com/sharer.php?s=100&p[title]= ' + title + '&p[summary]=' + desc + '&p[url]=' + linkUrl + '&p[images][0]=', 'sharer', 'toolbar=0,status=0');
    }
    else if (sitename == 'twitter') {
        window.open('http://twitter.com/home?status=Title ' + desc + '  Page Url:' + linkUrl + '', 'twitter', 'toolbar=0,status=0');
    }
    else if (sitename == 'google') {
        linkUrl = "https://plus.google.com/share?url=" + escape(linkUrl);
        window.open(linkUrl, '', 'toolbar=0,status=0');
    }
}
 
</script>
 
 

 Now you can call "shareData(param)" JavaScript method from your page by changing the appropirate input Parameter(facebook,twitter,google) whenever the User clicks on respective share button.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...