【问题标题】:How to share the current page with the Facebook,LinkedIn and Twitter Share Button?如何使用 Facebook、LinkedIn 和 Twitter 分享按钮分享当前页面?
【发布时间】:2017-10-30 16:13:29
【问题描述】:

很抱歉,如果这个问题已经被问过,但这种情况不同。我正在尝试制作一个共享当前 URL 的 Facebook 按钮,但我不知道该怎么做。我的问题是:我应该放什么而不是“主页”,以便这些按钮共享用户当前所在的页面而不是特定的网址? 这是当前代码的样子(我用主页替换了网站的 URL):

  <a href="http://www.facebook.com/sharer.php?u='homepage' target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-facebook-4-icon-32.png" alt="Facebook">
</a>

<!-- LinkedIn -->
<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=homepage" target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-linkedin-4-icon-32.png" alt="LinkedIn">
</a>

<!-- Twitter -->
<a href="https://twitter.com/share?url=homepage" target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-twitter-4-icon-32.png" alt="Twitter">
</a>

【问题讨论】:

标签: php html facebook twitter linkedin


【解决方案1】:
// Get the current URL
<?php
$Url = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$Url .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
?>
<a href="http://www.facebook.com/sharer.php?u=<?php echo $Url; ?>" target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-facebook-4-icon-32.png" alt="Facebook">
</a>

<!-- LinkedIn -->
<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=<?php echo $Url; ?>" target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-linkedin-4-icon-32.png" alt="LinkedIn">
</a>

<!-- Twitter -->
<a href="https://twitter.com/share?url=<?php echo $Url; ?>" target="_blank" style="text-decoration:none">
    <img src="http://image.noelshack.com/fichiers/2015/25/1434621881-iconmonstr-twitter-4-icon-32.png" alt="Twitter">
</a>

【讨论】:

  • @DumontIrou 感谢您的评论。你能把它标记为完成吗?
猜你喜欢
  • 1970-01-01
  • 2016-01-09
  • 2017-09-15
  • 2011-11-25
  • 1970-01-01
  • 2012-04-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多