有没有办法制作Facebook分享按钮,可以在墙上或新闻动态中发布自定义文本?
有没有办法制作Facebook分享按钮,可以在墙上或新闻动态中发布自定义文本?
<a title="send to Facebook"
href="http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_SUMMARY&p[url]=YOUR_URL&p[images][0]=YOUR_IMAGE_TO_SHARE_OBJECT"
target="_blank">
<span>
<img width="14" height="14" src="'icons/fb.gif" alt="Facebook" /> Facebook
</span>
</a>
<a class="facebook" target="_blank" onclick="return !window.open(this.href, 'Facebook', 'width=640,height=300')" href="http://www.facebook.com/sharer/sharer.php?u=YOUR_URL">Facebook</a>
等内容。 - Mateng<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail_image" />
如果页面不在你的控制范围内,那么请使用上面AllisonC分享的方法。
使用自己的按钮/链接/文本,然后可以通过以下方式使用模态视图类型的弹出窗口:
<script type= 'text/javascript'>
$('#twitterbtn-link,#facebookbtn-link').click(function(event) {
var width = 575,
height = 400,
left = ($(window).width() - width) / 2,
top = ($(window).height() - height) / 2,
url = this.href,
opts = 'status=1' +
',width=' + width +
',height=' + height +
',top=' + top +
',left=' + left;
window.open(url, 'twitter', opts);
return false;
});
</script>
其中 twitterbtn-link 和 facebookbtn-link 都是锚点的 ID。
if( window.open(.....) ) event.preventDefault();
,而不是只用return false;
。这样当打开窗口时,它只会防止默认行为(链接打开) - 并在没有打开窗口的情况下提供回退。 - jave.webYoutube使用此函数来共享
https://www.facebook.com/dialog/share?app_id=87741124305&href=https://youtube.com/watch?v=3hxE7Af98AI&feature=share&display=popup
下面是一种过时的解决方案,您可以使用从IJas提供的链接导出的函数。function openFbPopUp() {
var fburl = '';
var fbimgurl = 'http://';
var fbtitle = 'Your title';
var fbsummary = "your description";
var sharerURL = "http://www.facebook.com/sharer/sharer.php?s=100&p[url]=" + encodeURI(fburl) + "&p[images][0]=" + encodeURI(fbimgurl) + "&p[title]=" + encodeURI(fbtitle) + "&p[summary]=" + encodeURI(fbsummary);
window.open(
sharerURL,
'facebook-share-dialog',
'width=626,height=436');
return false;
}
如果使用FB JavaScript SDK,您也可以使用最新的FB.ui函数来获得更加可控的回调函数。
参考:FB.ui
function openFbPopUp() {
FB.ui(
{
method: 'feed',
name: 'Facebook Dialogs',
link: 'https://developers.facebook.com/docs/dialogs/',
picture: 'http://fbrell.com/f8.jpg',
caption: 'Reference Documentation',
description: 'Dialogs provide a simple, consistent interface for applications to interface with users.'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
您有几个选项:
<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'This is the content of the "name" field.',
link: 'URL which you would like to share ',
picture: ‘URL of the image which is going to appear as thumbnail image in share dialogbox’,
caption: 'Caption like which appear as title of the dialog box',
description: 'Small description of the post',
message: ''
}
);
});
});
</script>
<a onclick="return !window.open(this.href, '分享到Facebook', 'width=640, height=536')" href="https://www.facebook.com/sharer/sharer.php?u=href=$url&display=popup&ref=plugin" target="_window"><img src='/_img/icons/facebook.png' /></a>
$url变量应定义为要共享的URL。
您可以将AllisonC的想法与window.open
函数结合起来使用:
http://www.w3schools.com/jsref/met_win_open.asp
function openWin(url) {
myWindow = window.open(url, '', 'width=800,height=400');
myWindow.focus();
}
然后在每个链接上,您调用openWin函数并传入正确的社交网络URL。
试试这个网站http://www.sharelinkgenerator.com/。希望能帮到你。