现在不少网页为了更好的展示和推荐自己的优秀作品,采用了与常见社交网络相结合的方式。
这方面做得比较专业的可以参考网站http://tj.see-say.com/,该网站对该功能进行了封装,可以直接引入其提供的js插件。
但是对于想通过简单方式并不引用第三方文件的情况下,我们可以自己很方便的实现,今天我给大家奉献该功能实现代码,谢谢大家的关注(转载请注明来自ocean ocl):
1
2
3
Share my paper
4
5
6
7 a{
8 text-decoration:none;/*去除超链接下划线*/
9 }
10 img{
11 border: 0;;/*去除超链接图片蓝色边框*/
12 }
13
14
15
16
文章主内容块
17
18
19
20
21
22 var thisTitle=document.title;
23 var thisUrl=document.location.href;
24 //分享转发地址
25 var sinaUrl="http://v.t.sina.com.cn/share/share.php?title="+encodeURIComponent(thisTitle)+"&url="+encodeURIComponent(thisUrl);
26 var qqBlogUrl='http://v.t.qq.com/share/share.php?title='+encodeURIComponent(thisTitle)+'&url='+encodeURIComponent(thisUrl);
27 var qqZoneUrl='http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title='+encodeURIComponent(thisTitle)+'&url='+encodeURIComponent(thisUrl);
28 var renrenUrl='http://share.renren.com/share/buttonshare?title='+encodeURIComponent(thisTitle)+'&link='+encodeURIComponent(thisUrl);
29 var kaixinUrl='http://www.kaixin001.com/repaste/share.php?rtitle='+encodeURIComponent(thisTitle)+'&rurl='+encodeURIComponent(thisUrl);
30
31
32 
33
34
35
36 
37
38
39
40
41
42 
43
44
45
46
47
48 
49
50
51
52
53
54 
55
56
57
58
59
60 
61
62
63
64
65
66 (function(){
67 var postMsg = {
68 url:location.href,
69 to:'qqmail',
70 desc:'',
71 summary:'',
72 title:'',
73 site:'',
74 pics:''
75 };
76 var str = [];
77 for(var i in postMsg){
78 str.push(i + '=' + encodeURIComponent(postMsg[i]||''));
79 }
80 var qqmailHtml=["
'].join("");
81 document.write(qqmailHtml);
82 })();
83
84
85
86
87
88
效果如下:
以下是许多网站常用的分享实现代码:
document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000)