我使用以下代码实现了Facebook共享对话框。很偶然,它弹出一个共享对话框。 97%的时间,它只刷新页面。
感谢任何帮助。
<a href="someurl.com/some-article" data-image="myimage.jpg" data-title="My Article Title" data-desc="My description" class="btnShare">Share</a>
<script type="text/javascript">
window.fbAsyncInit = function(){
FB.init({
appId: 'myappID', status: true, cookie: true, xfbml: true });
};
(function(d, debug){var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if(d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id;
js.async = true;js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);}(document, /*debug*/ false));
function postToFeed(title, desc, url, image){
var obj = {method: 'feed',link: url, picture: 'http://www.url.com/images/'+image,name: title,description: desc};
function callback(response){}
FB.ui(obj, callback);
}
$('.btnShare').click(function(){
elem = $(this);
postToFeed(elem.data('title'), elem.data('desc'), elem.prop('href'), elem.data('image'));
return false;
});
</script>