我想在我的网站上添加 Facebook 分享按钮,该按钮应该只在墙上发布一些内容。谁想分享它。我用这段代码来做到这一点。 但我想通过链接分享图像和一些描述。 如何为此编码 url。
<!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>
最佳答案
我相信咨询一下FB Developers API documentation会好得多有一些功能可以自动生成正确的代码。
如果您喜欢,它甚至可以自动显示有多少人已经分享了此内容。
关于javascript - Facebook 分享按钮 - JavaScript/jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31847025/