2013-02-12 65 views
12

FB共享器彈出窗口顯示頁面的數據,而不是我在php鏈接中插入的元數據。facebook共享器彈出窗口

<a href="http://www.facebook.com/sharer/sharer.php?s=100&p%5Btitle%5D=Google&p%5Burl%5D=http%3A%2F%2Fwww.google.com&p%5Bsummary%5D=Google search engine&p%5Bimages%5D%5B0%5D=https://www.google.com/images/srpr/logo3w.png 
"onClick="return fbs_click(626, 305)" target="_blank" title="Share">FACEBOOK</a> 

看來要由JavaScript

<script type="text/javascript"> 
function fbs_click(width, height) { 
var leftPosition, topPosition; 
leftPosition = (window.screen.width/2) - ((width/2) + 10); 
topPosition = (window.screen.height/2) - ((height/2) + 50); 
var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=no,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no"; 
u=location.href; 
t=document.title; 
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', windowFeatures); 
return false; 
} 
</script> 

如何顯示在彈出窗口中正確的數據引起的?

回答

49

如果你想添加自定義元數據,使用下面的代碼:

<a id="fb-share" style='text-decoration:none;' type="icon_link" onClick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_DESCRIPTION&p[url]=YOUR_URL&p[images][0]=YOUR_IMAGE','sharer','toolbar=0,status=0,width=580,height=325');" href="javascript: void(0)">Share</a> 

UPDATE:

我寫了Facebook的分享一點的JS代碼。

的Javascript:

function fbShare(url, title, descr, image, winWidth, winHeight) { 
     var winTop = (screen.height/2) - (winHeight/2); 
     var winLeft = (screen.width/2) - (winWidth/2); 
     window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width='+winWidth+',height='+winHeight); 
    } 

HTML:

<a href="javascript:fbShare('http://jsfiddle.net/stichoza/EYxTJ/', 'Fb Share', 'Facebook share popup', 'http://goo.gl/dS52U', 520, 350)">Share</a> 
+0

完美,謝謝:)現在,如果我只能在頁面中間的彈出而不是左上角.. – no0ne 2013-02-12 12:52:54

+0

@ThomasBLund檢查我編輯的答案,一切工作正常:) – Stichoza 2013-02-13 08:45:34

+0

這是一個繼續(和解決方案)我的另一個問題「og元標籤爲幾個分享按鈕」 - http://stackoverflow.com/questions/14818698/open-graph-meta-tags-for-several-share-buttons - 謝謝Stichoza – no0ne 2013-02-13 09:38:07