為網站快速添加社交平台「一鍵關注」功能,最穩妥的方式是嵌入各平台官方提供的 iframe 組件。本文匯總四大主流平台(新浪微博、QQ空間、人人網、騰訊微博)的官方嵌入代碼,開箱即用。
<iframe
width="120"
height="24"
frameborder="0"
allowtransparency="true"
marginwidth="0"
marginheight="0"
scrolling="no"
border="0"
src="https://widget.weibo.com/relationship/followbutton.php?language=zh_cn&width=120&height=24&uid=1756720421&style=2&btn=red&dpc=1">
</iframe>
關鍵參數:
uid:目標用戶數字 ID(需從微博主頁或 API 獲取)style:按鈕樣式(1-4)btn:按鈕顏色(red/blue/green 等)dpc:是否顯示粉絲數(1=顯示)<iframe
src="https://open.qzone.qq.com/like?url=https://user.qzone.qq.com/1839458293&type=button_num&width=120&height=24&style=3"
allowtransparency="true"
scrolling="no"
border="0"
frameborder="0"
style="width:120px;height:24px;border:none;overflow:hidden;">
</iframe>
關鍵參數:
url:QQ 空間主頁地址(含 QQ 號)type:按鈕類型(button_num 顯示計數)style:樣式代碼<iframe
src="https://www.connect.renren.com/like?url=https://page.renren.com/699049347"
style="width:140px;height:23px;"
scrolling="no"
frameborder="0"
allowTransparency="true">
</iframe>
關鍵參數:
url:人人主頁/頁面地址<iframe
id="previewmc"
height="24"
src="https://follow.v.t.qq.com/index.php?c=follow&a=quick&name=yanghaonan7758&style=5&t=1336022961842&f=0"
frameborder="0"
width="125"
allowtransparency="true"
scrolling="no">
</iframe>
關鍵參數:
name:騰訊微博用戶名style:按鈕樣式t:時間戳(防緩存)f:是否顯示粉絲數<div class="social-follow"> 包裹,便於 CSS 佈局控制max-width: 100% 防止移動端溢出https:// 協議(現多平台已支援)隨著平台開放策略調整,部分平台已停止維護 iframe 組件。推薦改用: