Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share content of my website on facebook

I have a website and on that I have a facebook button named as share. I want that when user clicks on that button the content of my webpage should share on his wall. My code is like this in my head tag of page:

<script>
    function fbs_click(){
        u = location.href;
        t = document.title;
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
        return false;
    }
</script>

I also know that u= url of your content page t= title or site name and this is inside the body tag:

<a rel="nofollow" href="http://www.facebook.com/share.php?u=http://lums.edu.pk/event-detail/lecture-on-citation-management-and-referencing-1133"
class="fb_share_button" onclick="return fbs_click()" target="_blank"  
style="text-decoration:none;">Share</a>

?u is the link I want to share. This code open a share page for me, and share just my url not the content of my page. My content includes an image, tittle and detail (I'm fetching these values from database table). Please some one help me.

like image 337
user1885057 Avatar asked Dec 07 '12 10:12

user1885057


2 Answers

Have a look over OpenGraph tags like the ones below :

<meta property="og:title" content="TITLE" /> 
<meta property="og:image" content="URL" /> 
<meta property="og:description" content="DESCRIPTION" /> 
<meta property="og:url" content="URL" />
like image 61
Sorin Trimbitas Avatar answered Nov 13 '22 07:11

Sorin Trimbitas


Finally I got my solution.This is actual code that is doing job for me . I was mis handleing ?u of my link.It should be like this

 ?u=http%3A%2F%2Fmywebsite.com%2Fcontent+of+my+page" target="_blank">this link</a>
like image 2
user1885057 Avatar answered Nov 13 '22 05:11

user1885057