All*_*onC 92
我们使用这样的东西[在一行中使用]:
<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>
Run Code Online (Sandbox Code Playgroud)
Sha*_*anK 30
要给facebook分享自定义参数,最好只给出链接,facebook会自动从你正在分享的页面中获取其标题+描述+图片.为了"帮助"facebook API找到这些东西,你可以将以下内容放在你正在共享的页面的标题中:
<meta property="og:title" content="title" />
<meta property="og:description" content="description" />
<meta property="og:image" content="thumbnail_image" />
Run Code Online (Sandbox Code Playgroud)
如果页面不在您的控制之下,请使用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>
Run Code Online (Sandbox Code Playgroud)
其中twitterbtn-link和facebookbtn-link都是锚点的ID.
Bha*_*h B 12
使用此功能派生自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;
}
Run Code Online (Sandbox Code Playgroud)
或者,如果使用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.');
}
}
);
}
Run Code Online (Sandbox Code Playgroud)
你有几个选择:
您可以使用Facebook提供的异步JavaScript SDK并设置其参数值来自定义Facebook共享对话框
看看下面的代码:
<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>
Run Code Online (Sandbox Code Playgroud)
在复制和粘贴以下代码之前,必须先初始化SDK并设置jQuery库.请点击这里逐步了解如何设置相同的信息.
| 归档时间: |
|
| 查看次数: |
188729 次 |
| 最近记录: |