1. 程式人生 > >社交網站和微博一鍵分享的程式碼

社交網站和微博一鍵分享的程式碼

在社交網站和微博滿天飛的時候,怎麼讓自己網頁快速分享給好友?下面介紹開心網,人人網,新浪微博和騰訊微博一鍵分享的方法。

在HTML程式碼中加入如下

<a id="share2kaixin" href="#" target="_blank"><img src="images/p2_10.gif" width="16" height="28" alt="分享到開心網" /></a>
<a id="share2renren" href="#" target="_blank"><img src="images/p2_11.gif" width="16" height="28" alt="分享到人人網" /></a>
<a id="share2sina" href="#" target="_blank"><img src="images/p2_12.gif" width="16" height="28" alt="分享到新浪微博" /></a>
<a id="share2qq" href="#" target="_blank"><img src="images/p2_13.gif" width="16" height="28" alt="分享到騰訊微博" /></a>


在網頁尾部加入如下Javascript程式碼

<script type="text/javascript">
var p_url = encodeURIComponent(top.location.href);
var p_title = encodeURIComponent(top.document.title);
var p_pic = "";
var share_kaixin = document.getElementById("share2kaixin");
var share_renren = document.getElementById("share2renren");
var share_sina = document.getElementById("share2sina");
var share_qq = document.getElementById("share2qq");
if(share_kaixin) share_kaixin.href = "http://www.kaixin001.com/repaste/share.php?rurl=" + p_url+"&rtitle="+p_title + "&rcontent=" + p_url;
if(share_renren) share_renren.href = "http://share.renren.com/share/buttonshare.do?link=" + p_url + "&title=" + p_title;
if(share_sina) share_sina.href = "http://v.t.sina.com.cn/share/share.php?url="+ p_url+"&title="+p_title+"&source={source}&sourceUrl={sourceUrl}&content=utf8&pic="+p_pic;
if(share_qq) share_qq.href = "http://v.t.qq.com/share/share.php?url="+p_url+"&title="+p_title+"&site={site}n&pic="+p_pic;
</script>

新浪微博的分享可以z指定{source}和{sourceUrl},騰訊微博可以指定{site},將這幾個變數替換成你想要的內容即可。
這樣你的網頁就擁有一鍵分享功能。