2014-04-19 61 views
0

我想添加一個Facebook共享按鈕,但彈出窗口不顯示正確的參數。這是我的代碼:Facebook共享按鈕參數不起作用

<?php 

$title=urlencode('Title of the iFrame Tab'); 
$url=urlencode('http://my-domain/index.php?langue=eng&table_pub=publication_eng&id=22&rub=publication'); 
$summary=urlencode('Custom message here'); 
$image=urlencode('http://my-domain/img.png'); 
?> 
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" href="javascript: void(0)">Share</a> 

但這個代碼總是告訴我一個彈出這樣的: enter image description here

+0

我跟着這篇文章,它幫助我找到合適的解決方案: http://www.hyperarts.com/blog/tutorial-how-to-add-facebook-share-button-to-your-web -site-pages/ – Aminesrine

回答

0

使用Facebook javascropt SDK,

check this

window.fbAsyncInit = function() { 
    FB.init({ 
     appId  : '{your-app-id}', 
     status  : true, 
     xfbml  : true 
    }); 
    }; 

    (function(d, s, id){ 
    var js, fjs = d.getElementsByTagName(s)[0]; 
    if (d.getElementById(id)) {return;} 
    js = d.createElement(s); js.id = id; 
    js.src = "//connect.facebook.net/en_US/all.js"; 
    fjs.parentNode.insertBefore(js, fjs); 
    }(document, 'script', 'facebook-jssdk')); 

您的分享按鈕,

<a href="yoururl" data-image="yourimage" data-title="title" data-desc="Some description" class="fbshare">FBShare</a> 

在按一下按鈕,

$('.fbshare').click(function(){ 
    elem = $(this); 
    postToFeed(elem.data('title'), elem.data('desc'), 
    elem.prop('href'), 
    elem.data('image')); 

    return false; 
    }); 
+0

試過,但沒有奏效。點擊鏈接只是打開href網址。沒有臉書互動 – zekia