DIV CSS 佈局教程網

您现在的位置: DIV+CSS佈局教程網 >> 網頁腳本 >  >> WEB網站前端 >> 前端技巧
20 個社群分享按鈕程式碼大全(前端備用)
編輯:前端技巧     

讓使用者能一鍵把內容分享到各平台,是提升曝光最直接的方式。以下整理二十個常見平台的分享連結寫法,可分為「固定網址型」與「動態抓取型」兩類。

一、固定網址型(適合靜態頁面或後端組字串)

1. 新浪微博

<a href="https://v.t.sina.com.cn/share/share.php?url=https://www.jb51.net&title='分享內容'"
   target="_blank">新浪微博</a>

2. 騰訊微博

<a href="https://v.t.qq.com/share/share.php?url=https://www.jb51.net&title='分享內容'"
   target="_blank">騰訊微博</a>

3. 開心網

<a href="https://www.kaixin001.com/repaste/share.php?rurl=https://www.jb51.net&rcontent=https://www.baidu.com&rtitle=kaixin"
   target="_blank">開心網</a>

4. 豆瓣網

<a href="https://www.douban.com/recommend/?url=https://www.jb51.net&title=douban"
   target="_blank">豆瓣</a>

5. 人人網

<a href="https://share.renren.com/share/buttonshare.do?link=https://www.jb51.net"
   target="_blank">人人網</a>

6. 百度貼吧

<a href="https://tieba.baidu.com/f/commit/share/openShareApi?url=https://www.jb51.net&title=hello&desc=&pic="
   target="_blank">百度貼吧</a>

7. QQ 好友

<a href="https://connect.qq.com/widget/shareqq/index.html?title=qqhaoyou&url=https://www.jb51.net&desc=還不錯哦&pics=&site=優酷"
   target="_blank">QQ 好友</a>

8. QQ 空間

<a href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=https://www.jb51.net"
   target="_blank">QQ 空間</a>

9. 騰訊朋友

<a href="https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=pengyou&url=https://www.jb51.net"
   target="_blank">騰訊朋友</a>

10. 優酷空間

<a href="https://i.youku.com/u/share/?url=https://www.jb51.net&content='分享內容'"
   target="_blank">優酷空間</a>

11. 搜狐微博

<a href="https://t.sohu.com/third/post.jsp?content=utf-8&url=https://www.jb51.net&title=souhu"
   target="_blank">搜狐微博</a>

12. MSN

<a href="https://profile.live.com/badge/?url=https://www.jb51.net&Title=msn"
   target="_blank">MSN</a>

13. 貓撲

<a href="https://tt.mop.com/share/shareV.jsp?title=moptietie&pageUrl=https://www.jb51.net"
   target="_blank">MOP 貼貼</a>

14. 網易微博

<a href="https://t.163.com/article/user/checkLogin.do?link=https://www.jb51.net"
   target="_blank">網易微博</a>

二、動態抓取型(自動讀取目前頁面的網址與標題)

這類寫法用 JavaScript 即時取得 document.location.href 與 document.title,不需要為每篇文章手動改參數,適合套用在共用模板上。

15. 百度收藏

<a href="javascript:window.open('https://cang.baidu.com/do/add?it='+encodeURIComponent(document.title.substring(0,76))
  +'&iu='+encodeURIComponent(location.href)+'&fr=ien#nw=1',
  'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes'); void 0">百度搜藏</a>

16. QQ 書籤

<a href="javascript:window.open('https://shuqian.qq.com/post?from=3&title='+encodeURIComponent(document.title)
  +'&uri='+encodeURIComponent(document.location.href)+'&jumpback=2&noui=1',
  'favit','width=930,height=470,left=50,top=50,toolbar=no,menubar=no,location=no,scrollbars=yes,status=yes,resizable=yes'); void 0">QQ 書籤</a>

17. Google 書籤

<a href="javascript:window.open('https://www.google.com/bookmarks/mark?op=add&bkmk='
  +encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title)); void 0">Google</a>

18. Twitter

<a href="javascript:window.open('https://twitter.com/home?status='
  +encodeURIComponent(document.location.href)+' '+encodeURIComponent(document.title)); void 0">Twitter</a>

19. Facebook

<a class="fav_facebook" rel="nofollow"
   href="javascript:window.open('https://www.facebook.com/sharer.php?u='
   +encodeURIComponent(document.location.href)+'&t='+encodeURIComponent(document.title)); void 0">Facebook</a>

20. Delicious 書籤

<a href="javascript:window.open('https://del.icio.us/post?url='
  +encodeURIComponent(document.location.href)+'&title='+encodeURIComponent(document.title)+'&notes='); void 0">Delicious</a>

實務上的建議

這份清單中的多數平台(騰訊微博、開心網、人人網、貓撲、MSN、Delicious、Google 書籤等)服務已相繼停止或轉型,連結實際上已失效。今日若要在網站上加分享功能,合理的做法有兩種:

一、接入官方 SDK。Facebook 的 Share Button、X(Twitter)的 Web Intent、LINE 的分享 API 都提供現成的按鈕與參數規範,穩定且會隨平台更新維護。

二、使用第三方分享服務。像是百度分享、AddThis、ShareThis 這類服務,一次整合就能覆蓋大量平台,且相容性較好,不必逐一追蹤各家 API 變動。

另外提醒,若使用 javascript: 標籤,請注意它會被部分瀏覽器的安全政策阻擋,且對無障礙輔具不友善。較好的做法是把 href 設為真實網址,再用 JS 加上 target="_blank" 與 rel="noopener noreferrer"——最後這個屬性很重要,可避免新視窗透過 window.opener 反向操作你的頁面。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved