现在的位置: 首页 > 综合 > 正文

分享到新浪,人人,开心,天涯,豆瓣,搜狐,腾讯等的代码

2012年08月23日 ⁄ 综合 ⁄ 共 5916字 ⁄ 字号 评论关闭

/**
*  Copyright (C), 2011-2013
*  file name share_ico.js
*  author:wyl
*  version:1.0
*  date  20110503
*  function: Produce button of share icon  in the page. example sinaweibo renren kaixin
*  
*/
//function ss(){
//   
//    alert('share233223');
//}
function shareto(id){
var pic="";
var url=encodeURIComponent(document.location.href);
var title=encodeURIComponent(document.title);
var _gaq = _gaq ||[];

if(id=="fav"){
    addBookmark(document.title);
    return;
    }elseif(id=="tqq"){
    _gaq.push(['_trackEvent','SocialShare','Share','QZone',1]);
    window.open(' http://v.t.qq.com/share/share.php?url='+url);
    return;
    }elseif(id=="sina"){
    _gaq.push(['_trackEvent','SocialShare','Share','SinaT',1]);
    //window.open(' http://v.t.sina.com.cn/share/share.php?title='+title+'&url='+url+'&source=bookmark','_blank');
  
window.open("
http://v.t.sina.com.cn/share/share.php?url="+url+"&appkey=3347543801&title="+title+"&pic="+pic,"_blank","width=615,height=505");
    return;
    }elseif(id=="sohu"){
    _gaq.push(['_trackEvent','SocialShare','Share','sohu',1]);
  
window.open('
http://t.sohu.com/third/post.jsp?title='+title+'&link='+url+'&fr=ien#nw=1','_blank','scrollbars=no,width=600,height=450,left=75,top=20,status=no,resizable=yes');
    return;
    }elseif(id=="hexun"){
    _gaq.push(['_trackEvent','SocialShare','Share','hexun',1]);
    window.open('http://bookmark.hexun.com/post.aspx?url='+url+'&title='+title+'&imageurl='+pic,'_blank');
    return;
    }elseif(id=="douban"){
    _gaq.push(['_trackEvent','SocialShare','Share','Douban',1]);
  
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()}
    return;
    }elseif(id=="renren"){
    _gaq.push(['_trackEvent','SocialShare','Share','RenRen',1]);
    window.open(' http://www.connect.renren.com/share/sharer?url='+url+'&title='+title,'_blank','resizable=no');
    return;
    }elseif(id=="kaixin"){
    _gaq.push(['_trackEvent','SocialShare','Share','XianGuo',1]);
  

//http://www.kaixin001.com/~repaste/repaste.php?&rurl='+escape(d.location.href)+'&rtitle='+escape(d.title)+'&rcontent='+escape(d.title),'kaixin')
  
window.open('
http://www.kaixin001.com/~repaste/repaste.php?rurl='+url+'&rcontent='+title+'&rtitle='+title,'_blank');
    return;
    }elseif(id=="tianya"){
    share2Tianya(document.title,location.href,'');
//    _gaq.push(['_trackEvent', 'SocialShare', 'Share', 'Mail', 1]);
//    window.open(' http://t.tianya.cn/?url='+url+'&content='+title+'&title='+title,'_blank');
    //window.open(' http://www.tianya.cn/new/share/compose.asp?itemtype=tech&url='+url+'&strTitle='+title,'_blank');
  

//http://www.tianya.cn/new/share/compose.asp?itemtype=tech&item=665&strTitle=%CC%A8%CD%E5%B0%A2%C0%EF%C9%BD%D0%A1%BB%F0%B3%B5%B7%AD%B3%B5%A3%BA%CA%A5%C2%ED%B6%FB%B6%A8%D2%BD%D4%BA%B2%BF%B7%D6%CD%C5%D4%B1%B3%F6%D4%BA%20%5B%BF%B4%B6%AB%B7%BD%5D&strFlashURL=http://player.youku.com/player.php/sid/XMjYyNDE2NzEy/v.swf&strFlashPageURL=http://v.youku.com/v_show/id_XMjYyNDE2NzEy.html
    return;
    }
}

functionShareButtons(){
    document.write('<div class="social_share">');
    document.write('<strong>分享到: </strong>');
  
document.write('<a class="sharebutton" id="share_sina"
href="javascript:shareto(\'sina\');" title="分享到新浪微博"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/ico_sina.gif"
/></a>');
    document.write('<a class="sharebutton"
id="share_qzone" href="javascript:shareto(\'tqq\');"
title="分享到腾讯微博"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/btn_tqq.png"
/></a>');
    document.write('<a class="sharebutton"
id="share_douban" href="javascript:shareto(\'douban\');"
title="分享到豆瓣"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/btn_douban.png"/></a>');
  
document.write('<a class="sharebutton" id="share_xianguo"
href="javascript:shareto(\'kaixin\');" title="分享到开心网"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/btn_kaixin.gif"
/></a>');
    document.write('<a class="sharebutton"
id="share_googlebuzz" href="javascript:shareto(\'hexun\');"
title="分享到和讯"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/btn_hexun.gif"
/></a>');
    document.write('<a class="sharebutton"
id="share_baidu" href="javascript:shareto(\'sohu\');"
title="分享到搜狐微博"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/ico_sohu.png"
/></a>');
    document.write('<a class="sharebutton"
id="share_renren" href="javascript:shareto(\'renren\');"
title="分享到人人网"> <img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/btn_rr.png"
/></a>');
    document.write('<a class="sharebutton"
id="share_mail" href="javascript:shareto(\'tianya\');"
title="分享到天涯"><img
src="http://wyllife.blog.163.com/blog/./wp-content/themes/rbcpromotion/images/share_icon/ico_tianya.png"
/></a>');
    document.write('</div>');
}

++++++++++++++++++++++++++++++++++++++++++
分享到天涯有2种方法,分享到某个板块和分享到微博
具体的请参考 http://open.tianya.cn/Send.php
以下是转帖到某个板块的代码,可以整合到上面的例子里面
<script type="text/javascript" charset="utf-8">(function(){
  var param ={
    strFlashPageURL:location.href,/**转发帖子原地址*/
    strTitle:document.title,/**转发的帖子主题(可选,默认为所在页面的title)*/
    strContent:'',/**转发帖子的内容,可以用@添加关联用户(可选)*/
    strFlashURL:'',/**转发帖子的视频地址(可选)*/
    pIMG:'',/**转发帖子的图片地址(可选)*/
    itemtype:'tech'/**转发板块类型*/
    item:'402'/**转发板块ID*/
  }
  var temp =[];
  for(var p in param ){
    temp.push(p +'='+ encodeURIComponent( param[p]||''))
  }

document.write('<a target="_blank"
href="http://www.tianya.cn/new/share/compose.asp?'+ temp.join('&')
+'"><img
src="http://static.tianyaui.com/global/open/images/shareiconM.gif"></a>')
})()
</script>

抱歉!评论已关闭.