2014-03-26 40 views
0

代碼1:如何通過自定義參數在Facebook上共享資源的鏈接

<a id="button" rel="nofollow" href="http://www.facebook.com/share.php?" onclick="return fbs_click()" target="_blank"> 
<script> 
    function fbs_click() { 
     u=location.href; 
     t=document.title;   
     window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t), 
       'sharer', 
       'toolbar=0,status=0,width=626,height=436'); 

      return false; 
     } 

這裏標題「T」是行不通的,但我想顯示自定義標題,摘要,URL和圖像所以,我想這樣的事情

代碼2:

<a id="button"   href="http://www.facebook.com/sharer.php? 
         s=100 
         &p[url]=<?php echo $pressurl;?> 
         &p[images][0]=http://myurl/images/linkedin_image.png 
         &p[title]=mytitle 
         &p[summary]=containsummary      "> 

在這兩種情況下都沒有任何事情發生,它會自動從上面提到的url中獲取一些內容(標題,圖片,摘要),我想在facebook共享頁面顯示自定義標題,圖片和摘要,我dono如何使用og元標記和什麼s = 100這意味着什麼? ..

回答

9

除了在Facebook上使用sharer.php腳本,您還可以使用Facebook JavaScript SDK創建自定義共享對話框。

<!-- include Facebook JavaScript SDK --> 

<!-- share link --> 
<a href="#" class="share-btn">Share to Facebook</a> 

<script type="text/javascript"> 
function fb_share() { 
    // facebook share dialog 
    FB.ui({ 
     method: 'feed', 
     name: "Your Page Title", 
     link: "https://www.webniraj.com/link-to-page/", 
     picture: "https://stackexchange.com/users/flair/557969.png", 
     caption: "Some description here" 
    }, function(response) { 
     // do nothing 
    }); 

} 

// add click event to link using jQuery 
$(document).ready(function(){ 
    $('.share-btn').on('click', fb_share); 
}); 
</script> 

這將創建一個不錯的彈出分享至Facebook,你可以輕鬆地更改標題,描述,並在JavaScript的圖片屬性。 Working demo available here

+0

演示不起作用 - 「無法加載URL:此URL的域未包含在應用程序的域中」 – andrewb

+0

感謝您告訴我。鏈接已更新。 –

相關問題