zoukankan      html  css  js  c++  java
  • 分享到国内各SNS网站的代码

    现在SNS网站极为广泛,通过SNS的网络化和人际关系传播推广内容已经是各个网站经常采用的手段。

    也有一些网站或者组织提供了相应的集成工具 比如 
    http://www.jiathis.com/getcode/ 等,这类工具的特点是强大,完善,覆盖面广,当然如果你只需要主要的几个,也可以自己定义。
    其实分享到各个网站的功能是通过 各SNS网站的一个连接接口实现的。只要分析掌握了各个网站分享连接的组成规律,再用脚本等进行组合,生成相应连接地址即可。

    下为笔者写的一个简单的分享功能,它有简单的设置功能,设置分享的连接和标题,如果不设置,则默认取当前页面的URL 和 title

    分享到SNS网站代码
    /*
    *Share Tools 2011-06-16    
    *全局设置格式
    sharetools.config
    */
    var sharetools = sharetools || {};
    sharetools.config 
    = {
        title:
    "",
        url:
    "",
        pretxt:
    ""
        };
    sharetools._appkey 
    = encodeURI("KEY需要你自己申请");        
    sharetools._site 
    = 'http://i.qsl.cn';
    sharetools.shareurls 
    = [
        
    'http://v.t.qq.com/share/share.php?url=$$SHAREURL&title=$$SHARETITLE' + '&appkey='+ sharetools._appkey + '&site=' + sharetools._site,
        
    'http://v.t.sina.com.cn/share/share.php?url=$$SHAREURL&title=$$SHARETITLE',
        
    'http://www.kaixin001.com/repaste/share.php?rurl=$$SHAREURL&rcontent=$$SHAREURL&rtitle=$$SHARETITLE',
        
    'http://share.renren.com/share/buttonshare.do?link=$$SHAREURL&title=$$SHARETITLE',
        
    'http://www.douban.com/recommend/?url=$$SHAREURL&title=$$SHARETITLE',
        
    'http://bai.sohu.com/share/blank/add.do?link=$$SHAREURL',
        
    'http://apps.hi.baidu.com/share/?url=$$SHAREURL',
        
    'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=$$SHAREURL&title=$$SHARETITLE'
        ];
    sharetools.snstitles 
    = [
        
    '分享到腾讯微博',
        
    '分享到新浪微博',
        
    '分享到开心网',
        
    '分享到人人网',
        
    '分享到豆瓣',
        
    '分享到搜狐白社会',
        
    '分享到百度空间',
        
    '分享到QQ空间'
    ];    
    sharetools.init 
    = function(id){
        sharetools.id 
    = id;
        
    var sharecnt = $("#"+sharetools.id);
        
    if(!sharecnt.length) return;
        
    var sharetoolscss = $("#sharetoolscss");
        
    if(!sharetoolscss.length){
            $(
    '<link type="text/css" href="http://stc.qsl.cn/styles/i/sharetools.css" rel="stylesheet" media="all" id="sharetoolscss" >').appendTo($("head"));
            }
        
    var temp = [],urls =sharetools.shareurls ,len = urls.length;
        sharetools.url 
    = sharetools.config.url || window.location.href.toString();
        sharetools.title 
    = sharetools.config.title || document.title;
        sharetools.url 
    = encodeURIComponent(sharetools.url);
        sharetools.title 
    = encodeURIComponent(sharetools.title);
        
    for(var i=0; i<len; i++ ){
            
    var url = urls[i].replace(/\$\$SHAREURL/g,sharetools.url).replace(/\$\$SHARETITLE/g,sharetools.title),
                sns 
    = sharetools.snstitles[i];        
            temp.push(
    '<a href=',url,' title= ',sns,' rel="nofollow" target = "_blank" class="snsadd add_',i,'"></a>');
            }
        sharecnt.html(sharetools.config.pretxt
    +temp.join(""));

    使用方法:

    <div id="shareContent"></div>
    <script>
    sharetools.config 
    = {
     title:
    "登陆QSL.cn,免费抢8月6日鸟巢超级杯门票",
    url:invitation_link,
    pretxt:
    "分享到:"  };
       sharetools.init(
    "shareContent"); 

    </script> 

    使用效果: 

     http://i.qsl.cn/supercup/

  • 相关阅读:
    Vasya and Endless Credits CodeForces
    Dreamoon and Strings CodeForces
    Online Meeting CodeForces
    数塔取数 基础dp
    1001 数组中和等于K的数对 1090 3个数和为0
    1091 线段的重叠
    51nod 最小周长
    走格子 51nod
    1289 大鱼吃小鱼
    POJ 1979 Red and Black
  • 原文地址:https://www.cnblogs.com/trance/p/2118407.html
Copyright © 2011-2022 走看看