简体   繁体   English

Facebook分享按钮-JavaScript / jQuery

[英]Facebook share button - JavaScript/jQuery

I want to add facebook share button on my website, that should just post some content on the wall. 我想在我的网站上添加Facebook分享按钮,该按钮应该只在墙上张贴一些内容。 who want to share it.I used this code to do that. 谁想要共享它。我使用此代码来做到这一点。 but i want to share image and some description with link. 但我想与链接分享图片和一些描述。 how encode url for this. 如何为此编码网址。

 <!DOCTYPE html>
<html>
<head>
<meta property="og:title" content="Your title" /> 
<meta property="og:description" content="Your description" />
<script>
function share() {
    var width = 626;
    var height = 436;
    var yourPageToShare = location.href;
    var sharerUrl = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(yourPageToShare);
    var l = window.screenX + (window.outerWidth - width) / 2;
    var t = window.screenY + (window.outerHeight - height) / 2;
    var winProps = ['width='+width,'height='+height,'left='+l,'top='+t,'status=no','resizable=yes','toolbar=no','menubar=no','scrollbars=yes'].join(',');
    var win = window.open(sharerUrl, 'fbShareWin', winProps);
}
</script>
</head>
<body>

    <input type="button" value="Share" onclick="share();">

</body>
</html>  

I believe it is much better to cunsult FB Developers API documentation There are some features could generate the proper code automatically. 我认为最好咨询FB Developers API文档 。有些功能可以自动生成正确的代码。

If you like it could even automatically show how many people already shared this. 如果您愿意,它甚至可以自动显示已经分享了多少人。

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

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