Javascript 在Twitter上插入标题';推特';或Facebook';比如';给Fancybox?
当我点击一张图片并点击Twitter或Facebook的共享按钮时,它会与图片链接共享页面标题。有没有办法把图片的标题插入其中?Fancybox获取图像的Javascript 在Twitter上插入标题';推特';或Facebook';比如';给Fancybox?,javascript,jquery,facebook,twitter,fancybox,Javascript,Jquery,Facebook,Twitter,Fancybox,当我点击一张图片并点击Twitter或Facebook的共享按钮时,它会与图片链接共享页面标题。有没有办法把图片的标题插入其中?Fancybox获取图像的title属性(即“第一个标题”、“第二个标题”),但我不知道如何在实际tweet中实现这一点。我在网上找不到任何有关这方面的信息 小提琴: HTML JS $(“.fancybox”) .attr('rel','gallery') .fancybox({ beforeShow:函数(){ 如果(本标题){ //新线 this.title+
title
属性(即“第一个标题”、“第二个标题”),但我不知道如何在实际tweet中实现这一点。我在网上找不到任何有关这方面的信息
小提琴:
HTML
JS
$(“.fancybox”)
.attr('rel','gallery')
.fancybox({
beforeShow:函数(){
如果(本标题){
//新线
this.title+='
';
//添加tweet按钮
此.title+='';
//添加类似FaceBook的按钮
此.title+='';
}
},
afterShow:function(){
//渲染tweet按钮
twttr.widgets.load();
},
助手:{
标题:{
类型:“内部”
}
}
});
这是答案的一半
对于twitter,在添加任何社交媒体按钮之前,您可能需要在变量中捕获原始的标题。然后使用twitter的数据文本属性设置该值,如下所示:
beforeShow: function () {
if (this.title) {
var _title = this.title; // capture original title
// New line
this.title += '<br />';
// Add tweet button WITH data-text parameter
this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-text="' + _title + '" data-url="' + this.href + '">Tweet</a> ';
// Add FaceBook like button
this.title += '{facebook iframe}';
}
},
beforeShow:函数(){
如果(本标题){
var _title=this.title;//捕获原始标题
//新线
this.title+='
';
//添加带有数据文本参数的tweet按钮
此.title+='';
//添加类似FaceBook的按钮
this.title+='{facebook iframe}';
}
},
请参见
注意:我不确定Facebook是否允许你传递这些信息(这将是答案的另一半)巴达宾巴达邦!非常感谢。对于Facebook按钮,我决定通过添加&;来添加“共享”按钮;share=true
对参数进行修改。
$(".fancybox")
.attr('rel', 'gallery')
.fancybox({
beforeShow: function () {
if (this.title) {
// New line
this.title += '<br />';
// Add tweet button
this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-url="' + this.href + '">Tweet</a> ';
// Add FaceBook like button
this.title += '<iframe src="//www.facebook.com/plugins/like.php?href=' + this.href + '&layout=button_count&show_faces=true&width=500&action=like&font&colorscheme=light&height=23" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:23px;" allowTransparency="true"></iframe>';
}
},
afterShow: function() {
// Render tweet button
twttr.widgets.load();
},
helpers : {
title : {
type: 'inside'
}
}
});
beforeShow: function () {
if (this.title) {
var _title = this.title; // capture original title
// New line
this.title += '<br />';
// Add tweet button WITH data-text parameter
this.title += '<a href="https://twitter.com/share" class="twitter-share-button" data-count="none" data-text="' + _title + '" data-url="' + this.href + '">Tweet</a> ';
// Add FaceBook like button
this.title += '{facebook iframe}';
}
},