分享到豆瓣、百度空间、新浪微博的纯js代码
在自己的网站主页上增加社会化分享按钮,是有效提高自己网站流量的一种方法。
今天我在无争围棋网上增加了社会化按钮,根据我个人的习惯,我选择了豆瓣、百度空间、新浪微博、人人网、开心网等几个大型sns网站。下面是我的代码:
- function ShareCode(server_url, server_icon_url,text){
- var title = encodeURIComponent(document.title.substring(0,76));
- var url = encodeURIComponent(location.href);
- server_url = server_url.replace("{title}",title);
- server_url = server_url.replace("{url}",url);
- return "<a href="\" mce_href="\""javascript:window.open(\'"
- + server_url
- +"',\'_blank\',\'scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes\'); void 0\" style="\" mce_style="\""color:#000000;text-decoration:none;font-size:12px;font-weight:normal\"><SPAN style="\" mce_style="\""PADDING-RIGHT: 2px; PADDING-LEFT: 2px; FONT-SIZE: 12px; PADDING-BOTTOM: 0px; MARGIN-LEFT: 2px; CURSOR: pointer; PADDING-TOP: 5px\"><IMG alt="
- + text + " src="\" mce_src="\""
- + server_icon_url
- + "\" align=absMiddle border=0> "
- + text + "<\/SPAN><\/a>"
- }
- function WriteSNS()
- {
- document.writeln("<div id=\"socialbookmark\">");
- document.writeln(ShareCode("http://www.douban.com/recommend/?url={url}&title={title}",
- "http://t.douban.com/favicon.ico",
- "推荐到豆瓣"));
- document.writeln(ShareCode("http://apps.hi.baidu.com/share/?title={title}&url={url}",
- "http://www.baidu.com/favicon.ico",
- "转帖到百度空间"));
- document.writeln(ShareCode("http://v.t.sina.com.cn/share/share.php?title={title}&url={url}",
- "http://t.sina.com.cn/favicon.ico",
- "转发到新浪微博"));
- document.writeln(ShareCode("http://www.kaixin001.com/repaste/share.php?rtitle={title}&rurl={url}",
- "http://img1.kaixin001.com.cn/i/favicon.ico",
- "转贴到开心网"));
- document.writeln(ShareCode("http://share.renren.com/share/buttonshare.do?title={title}&link={url}",
- "http://s.xnimg.cn\/favicon-rr.ico",
- "转帖到人人网"));
- document.writeln("</div>");
- };
上面后台函数,一般放在.js文件中。在页面上需要添加分享按钮的地方,调用一次WriteSNS()函数,分享功能即大功告成:
<script type="text/javascript">WriteSNS();</script>