各平台一键转发代码

来源:互联网 发布:校园网络诈骗是什么 编辑:程序博客网 时间:2024/06/05 11:32

这里提供了一些流行的转帖方式,注意这只是示例,你可能需要改动代码,而且每个平台可能会提供多种方式转帖。同时每个开发平台的接口处于变化之中,请关注官方的更新。在页面最下方可以找到各平台的对应链接。


豆瓣的“推荐到豆瓣”按钮

<a href="javascript:void(function(){var d=document,e=encodeURIComponent,s1=window.getSelection,s2=d.getSelection,s3=d.selection,s=s1?s1():s2?s2():s3?s3.createRange().text:'',r='http://www.douban.com/recommend/?url='+e(d.location.href)+'&title='+e(d.title)+'&sel='+e(s)+'&v=1',x=function(){if(!window.open(r,'douban','toolbar=0,resizable=1,scrollbars=yes,status=1,width=450,height=330'))location.href=r+'&r=1'};if(/Firefox/.test(navigator.userAgent)){setTimeout(x,0)}else{x()}})()"><img src="http://img2.douban.com/pics/fw2douban_s.png" alt="推荐到豆瓣" /></a>


人人网的站外分享按钮

<a href="javascript:void((function(s,d,e){if(/renren\.com/.test(d.location))return;var f='http://share.renren.com/share/buttonshare?link=',u=d.location,l=d.title,p=[e(u),'&title=',e(l)].join('');function%20a(){if(!window.open([f,p].join(''),'xnshare',['toolbar=0,status=0,resizable=1,width=626,height=436,left=',(s.width-626)/2,',top=',(s.height-436)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent));" title="分享到人人"><img src="http://a.xnimg.cn/imgpro/share/share-tinybtn.png" title="分享到人人"/></a>


新浪微博分享

<a href="javascript:void((function(s,d,e,r,l,p,t,z,c){var%20f='http://v.t.sina.com.cn/share/share.php?appkey=真实的appkey',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&source=',e(r),'&sourceUrl=',e(l),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=440,height=430,left=',(s.width-440)/2,',top=',(s.height-430)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','图片链接|默认为空','标题|默认当前页标题','内容链接|默认当前页location','页面编码gb2312|utf-8默认gb2312'));">分享至微博</a>

开心网转帖部件

<script src="http://rest.kaixin001.com/api/Repaste_js.php" type="text/javascript"></script><div id="kx001_btn_repaste"></div><script type="text/javascript">KX001_REPASTE_LINK.init(1,"转帖到开心网","#336699","#3366CC");</script>

除此之外,开心网还支持另外的方式转帖。详见 开心网转帖部件技术接口文档.pdf

分享到QQ空间

<script type="text/javascript">(function(){var p = {url:location.href,desc:'',/*默认分享理由(可选)*/summary:'',/*摘要(可选)*/title:'',/*分享标题(可选)*/site:'',/*分享来源 如:腾讯网(可选)*/pics:'' /*分享图片的路径(可选)*/};var s = [];for(var i in p){s.push(i + '=' + encodeURIComponent(p[i]||''));}document.write(['<a href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?',s.join('&'),'" target="_blank" title="分享到QQ空间">分享到QQ空间</a>'].join(''));})();</script>



搜狐微博分享

<a title="分享到搜狐微博" href="javascript:void((function(s,d,e,r,l,p,t,z,c){var f='http://t.sohu.com/third/post.jsp?',u=z||d.location,p=['&url=',e(u),'&title=',e(t||d.title),'&content=',c||'gb2312','&pic=',e(p||'')].join('');function%20a(){if(!window.open([f,p].join(''),'mb',['toolbar=0,status=0,resizable=1,width=660,height=470,left=',(s.width-660)/2,',top=',(s.height-470)/2].join('')))u.href=[f,p].join('');};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();})(screen,document,encodeURIComponent,'','','','','','utf-8'));" style="margin:0 0 0 20px;font-size:12px;font-family:'\5b8b\4f53';color:#369"><span style="display:inline-block;width:16px;height:16px;margin:0 3px 0.2em -20px;vertical-align:middle;background:url(http://s2.cr.itc.cn/img/t/152.png) no-repeat"></span>分享到搜狐微博</a>


最后提供分享到多个平台的函数

function jumpUrl(x){var url = '', e = encodeURIComponent, s = screen, d = document, wd = 0, hg = 0, u = d.location;var rcontent=e(' 转自 '+u.href+' '+d.title);if(x=='t'){url ="http://t.sohu.com/third/post.jsp?url="+e(u.href)+"&title="+rcontent+'&content=utf-8';wd = 660;hg = 470;}else if(x=='bai'){url ="http://bai.sohu.com/share/blank/addbutton.do?link="+e(u.href)+"&title="+e(d.title);wd = 480;hg = 340;}else if(x=='douban'){url ="http://www.douban.com/recommend/?url="+e(u.href)+"&title="+e(d.title);wd = 460;hg = 340;}else if(x=='weibo'){url='http://service.weibo.com/share/share.php?title='+rcontent+'&url='+e(u.href);          wd = 460;hg = 340;}else if(x=='renren'){url ="http://share.renren.com/share/buttonshare?link="+e(u.href)+"&title="+e(d.title);wd = 590;hg = 430;}else if(x=='kaixin'){url ="http://www.kaixin001.com/repaste/share.php?rurl="+e(u.href)+"&rtitle="+e(d.title)+'&rcontent='+rcontent;wd = 540;hg = 360;}else if(x=='itb'){var ctxt = $('contentText').getElementsByTagName('p').length>0?$('contentText').getElementsByTagName('p')[0].innerHTML.replace(/<[^>].*?>/g,'').substr(0,120):'';url ="http://tieba.baidu.com/i/sys/share?link="+e(u.href)+"&type=text&title="+e(d.title)+"&content="+e(ctxt);wd = 626;hg = 436;}else if(x=='qq'){url ="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url="+e(u.href)+'&desc='+rcontent;wd = 900;hg = 500;}function a(){if (!window.open(url, 'sohushare', ['toolbar=0,status=0,resizable=1,width='+ wd +',height='+ hg +',left='+ (s.width - wd) / 2+ ',top='+ (s.height - hg) / 2]))u.href = [url].join('');}if (/Firefox/.test(navigator.userAgent)){setTimeout(a, 0);}else{a();}}


参考:

  • 新浪微博开发平台 ShareCode
  • 在你的网站上添加“推荐到豆瓣”按钮
  • 人人网站外分享
  • 开心网开放平台转帖部件
  • 腾讯社区开发平台分享组件
  • 一键分享到搜狐微博

原创粉丝点击