【问题标题】:facebook Sharer popup windowfacebook 共享器弹出窗口
【发布时间】:2013-01-27 13:15:12
【问题描述】:

FB分享器弹窗显示的是页面的数据,不是我在php链接中插入的元数据。

<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>

如何在弹出窗口中显示正确的数据?

【问题讨论】:

    标签: php javascript facebook metadata


    【解决方案1】:

    我发现这个分享链接在研究后不再起作用,你应该在这个新的分享网址上更新你的功能

    href="https://www.facebook.com/sharer/sharer.php?u=&t=" title="Share on Facebook" target="_blank" onclick="window.open('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(document.URL) + '&t=' + encodeURIComponent(document.URL)); return false;"> </a>
    

    【讨论】:

      【解决方案2】:

      如果要添加自定义元数据,请使用以下代码:

      <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>
      

      更新:

      我为 Facebook Share 写了一点 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>
      

      【讨论】:

      • 完美,谢谢 :) 现在如果我只能在页面中间而不是左上角弹出窗口..
      • @ThomasBLund 查看我编辑的答案,一切正常 :)
      • 这是我关于“多个共享按钮的 og-meta 标签”的另一个问题的继续(和解决方案) - stackoverflow.com/questions/14818698/… - 谢谢 Stichoza
      • 请注意,详细参数(标题、摘要、图像)已被弃用并删除,stackoverflow.com/a/22969530/368691
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多