将 Facebook 分享按钮添加到静态 HTML 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5478702/
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
Add Facebook Share button to static HTML page
提问by aumanets
Is there any way to add a Facebook Share Buttonto a static HTML page? I've implemented a simple web site with no server side, just a bunch of html pages and I was abble to add a Like button because it is implemented with iFrame element. I have searched for a solution regarding the Share Buttonbefore posting here, but can't really find anything.
有没有办法将 Facebook分享按钮添加到静态 HTML 页面?我已经实现了一个没有服务器端的简单网站,只有一堆 html 页面,我能够添加一个 Like 按钮,因为它是用 iFrame 元素实现的。在这里发帖之前,我已经搜索了有关“共享按钮”的解决方案,但实际上找不到任何东西。
(Example of a share button can be seen on a youtube web site, on share section of each video.)
(分享按钮的例子可以在 YouTube 网站上的每个视频的分享部分看到。)
Any help is appreciated.
任何帮助表示赞赏。
采纳答案by jpea
You should be able to generate your own button code here: http://developers.facebook.com/docs/reference/plugins/like/
您应该能够在此处生成自己的按钮代码:http: //developers.facebook.com/docs/reference/plugins/like/
回答by PhobosK
This should solve your problem: FB Share button/dialog documentationGenereally speaking you can use either normal HTML code and style it with CSS, or you can use Javascript.
这应该可以解决您的问题:FB Share button/dialog documentation一般来说,您可以使用普通的 HTML 代码并使用 CSS 对其进行样式设置,也可以使用 Javascript。
Here is an example:
下面是一个例子:
<a href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fparse.com" target="_blank" rel="noopener">
<img class="YOUR_FB_CSS_STYLING_CLASS" src="img/YOUR_FB_ICON_IMAGE.png" width="22px" height="22px" alt="Share on Facebook">
</a>
Replace https%3A%2F%2Fparse.com, YOUR_FB_CSS_STYLING_CLASSand YOUR_FB_ICON_IMAGE.pngwith your own choices and you should be ok.
用你自己的选择替换https%3A%2F%2Fparse.com、YOUR_FB_CSS_STYLING_CLASS和YOUR_FB_ICON_IMAGE.png,你应该没问题。
Note:For the sake of your users' security use the HTTPS link to FB, like in the a's hrefattribute.
注意:为了您用户的安全,请使用到 FB 的 HTTPS 链接,就像在a的href属性中一样。
回答by Akmal Izzulhaq
<a name='fb_share' type='button_count' href='http://www.facebook.com/sharer.php?appId={YOUR APP ID}&link=<?php the_permalink() ?>' rel='nofollow'>Share</a><script src='http://static.ak.fbcdn.net/connect.php/js/FB.Share' type='text/javascript'></script>
回答by Piotr Ciszewski
Replace <url>
with your own link
替换<url>
为您自己的链接
<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><style> html .fb_share_link { padding:2px 0 0 20px; height:16px; background:url(http://static.ak.facebook.com/images/share/facebook_share_icon.gif?6:26981) no-repeat top left; }</style><a rel="nofollow" href="http://www.facebook.com/share.php?u=<;url>" onclick="return fbs_click()" target="_blank" class="fb_share_link">Share on Facebook</a>
回答by iMic
<div class="fb_share">
<a name="fb_share" type="box_count" share_url="<?php the_permalink() ?>"
href="http://www.facebook.com/sharer.php">Partilhar</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> </div> <?php } }
add_action('thesis_hook_byline_item','fb_share');