javascript 一个页面上的多个 Facebook 共享
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9279759/
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
Multiple Facebook Shares on One Page
提问by Curtis Mangione
I have a daily deal aggregator site and i can't get the Facebook share to work properly. There are lots of deals on each page and each one has it's own FB share so they can post it on their wall, friends walls etc.
我有一个每日交易聚合网站,但我无法让 Facebook 共享正常工作。每个页面上都有很多优惠,每个都有自己的 FB 分享,因此他们可以将其张贴在自己的墙上、朋友墙上等等。
here is the site so you can try the share: http://bit.ly/xFGzj5
这是网站,您可以尝试分享:http: //bit.ly/xFGzj5
Here is the code Im using now:
这是我现在使用的代码:
<!-- Each Deal has this button that links to FB -->
<a href="http://www.facebook.com/share.php?u=<?php echo urlencode($shareurl); ?>" onclick="return fbs_click('<?php echo urlencode($shareurl); ?>','<?php echo $title; ?>')" target="_blank"><img src="../../images/fb.png" border="0" alt="Share On Facebook" class="smicon" /></a>
<!--And here is the JS function:-->
<script>
function fbs_click(u,t) {
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>
With this method, right now the title is not working properly, and sometimes an image shows up, sometimes it doesn't. When an image does show there are about 200 thumbnails to choose from (depending on how many deals are on the page) so the user has to cycle through it until they find the right one.
使用这种方法,现在标题不能正常工作,有时显示图像,有时不显示。当图像确实显示时,大约有 200 个缩略图可供选择(取决于页面上的交易数量),因此用户必须循环浏览,直到找到合适的缩略图。
Ideally, I want the url/title working properly (obviously) and have the image go to that specific deal's image by default when they click the share button. Anyone have any ideas on how to make this work???
理想情况下,我希望 url/title 正常工作(显然),并在他们单击共享按钮时默认将图像转到该特定交易的图像。任何人对如何使这项工作有任何想法???
采纳答案by Nitzan Tomer
why are you taking this approach? i recommend using either the social widgets or the javascript sdk fb provides.
你为什么要采取这种方法?我建议使用社交小部件或 javascript sdk fb 提供。
for example, with the js sdk you can do this: https://developers.facebook.com/docs/reference/dialogs/send/
例如,使用 js sdk,您可以执行以下操作:https: //developers.facebook.com/docs/reference/dialogs/send/
as for the social widgets, you can add a like for each item: https://developers.facebook.com/docs/reference/plugins/like/
至于社交小部件,您可以为每个项目添加一个赞:https: //developers.facebook.com/docs/reference/plugins/like/
or send button: https://developers.facebook.com/docs/reference/plugins/send/
或发送按钮:https: //developers.facebook.com/docs/reference/plugins/send/
回答by Nico van Niekerk
Just remember to have the JS Function only once on your main page, otherwise it is loaded every time a page loads. That will prevent the images from disappearing. In .NET I added all the FB funcion-scripts in the Site.master page and it works fine.
请记住在您的主页上只使用一次 JS 函数,否则每次加载页面时都会加载它。这将防止图像消失。在 .NET 中,我在 Site.master 页面中添加了所有 FB funcion-scripts,它工作正常。