如何传递自定义参数在facebook sharer链接 [英] how to pass custom parameter in facebook sharer link
问题描述
代码1:
< a id =button =nofollow href =http://www.facebook.com/share.php? onclick =return fbs_click()target =_ blank>
< 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;
}
标题t无效,但我想显示自定义标题,摘要,网址和图片,因此,我尝试过类似的操作
strong>代码2:
< a id =buttonhref =http: facebook.com/sharer.php?
s = 100
& p [url] =<?php echo $ pressurizedl;?>
& p [images] [0] http://myurl/images/linkedin_image.png
& p [title] = mytitle
& p [summary] = containsummary>
在这两种情况下没有发生任何事情,它会自动从上面的内容我想在Facebook分享页面显示自定义标题,图像和摘要和我如何使用元标记和什么S = 100它的意思? ..
不使用Facebook上的sharer.php脚本,您可以使用Facebook JavaScript SDK创建自定义共享对话框。
<! - include Facebook JavaScript SDK - >
<! - 分享链接 - >
< a href =#class =share-btn>分享到Facebook< / a>
< script type =text / javascript>
function fb_share(){
// facebook share dialog
FB.ui({
method:'feed',
name:Your Page Title,
link:https://www.webniraj.com/link-to-page/,
图片:https://stackexchange.com/users/flair/557969.png,
caption:这里有一些描述
},function(response){
// do nothing
});
}
//使用jQuery添加点击事件
$(document).ready(function(){
$ -btn')。on('click',fb_share);
});
< / script>
这将创建一个漂亮的弹出窗口分享到Facebook,你可以很容易地更改标题,和图片属性。 此处提供工作演示。 p>
Code 1:
<a id="button" rel="nofollow" href="http://www.facebook.com/share.php?" onclick="return fbs_click()" target="_blank">
<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;
}
Here Title "t" is not working but i want to display custom title, summary, url and image so, I tried something like this
Code 2:
<a id="button" href="http://www.facebook.com/sharer.php?
s=100
&p[url]=<?php echo $pressurl;?>
&p[images][0]=http://myurl/images/linkedin_image.png
&p[title]=mytitle
&p[summary]=containsummary ">
In both the cases nothing happened it automatically get some content (title,image,summary) from the above mentioned url and I want to display custom title,image and summary in facebook share page and i dono how to use og meta tag and what s=100 it means?..
Instead of using the sharer.php script on Facebook, you can use the Facebook JavaScript SDK to make a custom share dialog.
<!-- include Facebook JavaScript SDK -->
<!-- share link -->
<a href="#" class="share-btn">Share to Facebook</a>
<script type="text/javascript">
function fb_share() {
// facebook share dialog
FB.ui( {
method: 'feed',
name: "Your Page Title",
link: "https://www.webniraj.com/link-to-page/",
picture: "https://stackexchange.com/users/flair/557969.png",
caption: "Some description here"
}, function( response ) {
// do nothing
} );
}
// add click event to link using jQuery
$(document).ready(function(){
$('.share-btn').on( 'click', fb_share );
});
</script>
This will create a nice popup for sharing to Facebook, and you can easily change the title, description, and picture attributes in the JavaScript. Working demo available here.
这篇关于如何传递自定义参数在facebook sharer链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!