简体   繁体   English

如何在Facebook上分享我的网站内容

[英]How to share content of my website on facebook

I have a website and on that I have a facebook button named as share. 我有一个网站,我有一个名为share的facebook按钮。 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: 我的代码在我的head标签页面中是这样的:

<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: 我也知道你的内容页面的u= url t= title或网站名称,这是在body标签内:

<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. 请有人帮助我。

Have a look over OpenGraph tags like the ones below : 看看下面的OpenGraph标签:

<meta property="og:title" content="TITLE" /> 
<meta property="og:image" content="URL" /> 
<meta property="og:description" content="DESCRIPTION" /> 
<meta property="og:url" content="URL" />

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>

This example is using JSP. 这个例子是使用JSP。 JS is based on top example. JS基于顶级示例。

<a id="fb_link" href="#fb_link" onclick="fbs_click('${product.id}');">Share me on FB</a>

function fbs_click(id) {
var url = 'http://www.facebook.com/sharer.php?u=' +
    encodeURIComponent('https://www.mysite.com.au/product/detail?advertiseId=') + id;
window.open(url, 'Share on FaceBook', 'left=20,top=20,width=550,height=400,toolbar=0,menubar=0,scrollbars=0,location=0,resizable=1');
return false;
}

Have to mention that for some magic reason location=0 doesn't work in my firefox ... 不得不提一下,由于某些神奇的原因,location = 0在我的firefox中不起作用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM