当我尝试使用以下代码打开Facebook Share对话框时,我遇到了jQuery click()函数的问题:
$(".like a").click(function (e) {
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');
e.preventDefault();
return false;
})
当我点击链接时,它打开一个没有描述,没有标题,没有URL的共享对话框。 使用此链接打开的相同网址效果很好:
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Insert text or an image here.</a>
生成参数的PHP代码在以下两种情况下均为:
<?php
$title=urlencode('Event');
$url=urlencode('http://www.my_site.com');
$summary=urlencode('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.');
$image=urlencode('http://www.yourdomain.com/images/share-thumbnail.jpg');
?>
------- -----更新
渲染代码Javascript函数:
window.open('http://www.facebook.com/sharer.php?s=100&p[title]=Event&p[summary]=1+Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipisicing+elit%2C+sed+do+eiusmod+tempor+incididunt+ut+labore+et+dolore+magna+aliqua.+Ut+enim+ad+minim+veniam%2C+quis+nostrud+exercitation+ullamco+laboris+nisi+ut+aliquip+ex+ea+commodo+consequat.+Duis+aute+irure+dolor+in+reprehenderit+in+voluptate+velit+esse+cillum+dolore+eu+fugiat+nulla+pariatur.+Excepteur+sint+occaecat+cupidatat+non+proident%2C+sunt+in+culpa+qui+officia+deserunt+mollit+anim+id+est+laborum.&p[url]=http%3A%2F%2Fwww.my_site.com&p[images][0]=http%3A%2F%2Fwww.yourdomain.com%2Fimages%2Fshare-thumbnail.jpg','sharer','toolbar=0,status=0,width=548,height=325');
渲染代码onclick():
onclick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=Event&p[summary]=1+Lorem+ipsum+dolor+sit+amet%2C+consectetur+adipisicing+elit%2C+sed+do+eiusmod+tempor+incididunt+ut+labore+et+dolore+magna+aliqua.+Ut+enim+ad+minim+veniam%2C+quis+nostrud+exercitation+ullamco+laboris+nisi+ut+aliquip+ex+ea+commodo+consequat.+Duis+aute+irure+dolor+in+reprehenderit+in+voluptate+velit+esse+cillum+dolore+eu+fugiat+nulla+pariatur.+Excepteur+sint+occaecat+cupidatat+non+proident%2C+sunt+in+culpa+qui+officia+deserunt+mollit+anim+id+est+laborum.&p[url]=http%3A%2F%2Fwww.my_site.com&p[images][0]=http%3A%2F%2Fwww.yourdomain.com%2Fimages%2Fshare-thumbnail.jpg','sharer','toolbar=0,status=0,width=548,height=325');"
感谢所有人的帮助
答案 0 :(得分:0)
我认为Facebook sharer.php不再接受查询字符串参数。
它会读取您要分享的网址上的开放图表标记。
因此,请确保您所分享的网址具有正确的标记。