在WordPress中获取弹出的共享链接


Get share links to popup in WordPress

我正在尝试使用这个弹出功能:

function popupwindow(url, title, w, h) {
  var left = (screen.width/2)-(w/2);
  var top = (screen.height/2)-(h/2);
  return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

在这些社交链接上:

<a href="https://www.facebook.com/sharer/sharer.php?u=<?php bloginfo( 'url' ); ?>" title="Share on Facebook"></a>
<a href="http://twitter.com/home?status=<?php the_title(); ?>+<?php bloginfo( 'url' ); ?>" title="Share on Twitter"></a>
<a href="https://plus.google.com/share?url=<?php bloginfo( 'url' ); ?>" title="Share on Google Plus"></a>

通常,我会这样做:

<a onclick="popupwindow('http://www.example.com', 'facebook',400,400);" href="javascript:void(0);">Share on Facebook</a>

但我知道PHP不能在Javascript中使用,因为它是服务器端和客户端。那么我该如何弹出这些链接呢?

上面的代码实际上应该可以工作,您可以像在第二个示例中使用a标记一样,将php与javascript函数放在一起。

如果你仔细阅读了评论,问题实际上是由JavaScript错误引起的。