php 如何在 facebook 上分享我网站的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13761019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to share content of my website on facebook
提问by user1885057
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:
我有一个网站,上面有一个名为 share 的 facebook 按钮。我希望当用户点击那个按钮时,我的网页内容应该在他的墙上分享。我的代码在页面的 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= urlof your content page t= titleor site name and this is inside the body tag:
我也知道u= url你的内容页面t= title或网站名称,这是在正文标签内:
<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.
?u 是我想分享的链接。此代码为我打开一个共享页面,并仅共享我的 url 而不是我页面的内容。我的内容包括图像、标题和细节(我从数据库表中获取这些值)。请有人帮助我。
采纳答案by user1885057
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 我的链接应该是这样的
?u=http%3A%2F%2Fmywebsite.com%2Fcontent+of+my+page" target="_blank">this link</a>
回答by Sorin Trimbitas
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" />
回答by Mircea Stanciu
This example is using JSP. JS is based on top example.
此示例使用 JSP。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 中不起作用......

