当我尝试使用以下代码打开 Facebook 共享对话框时,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。使用此链接打开的相同 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');"
感谢大家的帮助