一鍵分享QQ、微信、微博等


github上找到的,合並了一個二維碼在線支持API,直接修改樣式可用。

二維碼API說明網址:http://www.liantu.com/pingtai/

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
    <meta name="format-detection" content="telephone=no" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="pragma" content="no-cache" />
    <title>asdfasdfasdfdsaf</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        img {
            border: 0 none;
        }

        body {
            background: #eee;
        }

        .m-box {
            width: 800px;
            margin: 0 auto;
            padding: 20px;
            background: #fff;
        }

            .m-box p {
                margin: 0 0 10px;
            }

            .m-box .icn a {
                display: block;
                width: 55px;
                height: 35px;
                background: url('http://l.bst.126.net/rsc/img/weibo.png?035') no-repeat;
            }

            .m-box .icn .wb1 {
                background-position: 10px -216px;
            }

            .m-box .icn .wb2 {
                background-position: -190px -216px;
            }

            .m-box .icn .wb3 {
                background: url(http://l.bst.126.net/rsc/img/postshare/tieba24.png) 15px 0 no-repeat;
            }

            .m-box .icn .wb4 {
                background-position: -88px -215px;
            }

            .m-box .icn .wb5 {
                background-position: -138px -216px;
            }

            .m-box .icn .wb6 {
                background-position: -245px -216px;
            }

            .m-box .icn .wb7 {
                background-position: -300px -216px;
            }

            .m-box .icn .wb8 {
                background-position: -355px -216px;
            }

            .m-box .icn .wb9 {
                background-position: -415px -215px;
            }
    </style>
</head>

<body>
    <div class="m-box">
        <p>分享到微信,易信:</p>
        <div class="icn"><img src="http://qr.topscan.com/api.php?text=http://www.baidu.com&w=125" /></div>
    </div>

    <div class="m-box">
        <p>分享到新浪微博:</p>
        <div class="icn"><a class="wb1" onclick="shareToSinaWB(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到QQ空間:</p>
        <div class="icn"><a class="wb2" onclick="shareToQzone(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到百度貼吧:</p>
        <div class="icn"><a class="wb3" onclick="shareToTieba(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到豆瓣:</p>
        <div class="icn"><a class="wb4" onclick="shareToDouban(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到騰迅微博:</p>
        <div class="icn"><a class="wb5" onclick="shareToQQwb(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到人人網:</p>
        <div class="icn"><a class="wb6" onclick="shareToRenren(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到開心網:</p>
        <div class="icn"><a class="wb7" onclick="shareToKaixin(event)"></a></div>
    </div>

    <div class="m-box">
        <p>分享到facebook:</p>
        <div class="icn"><a class="wb8" onclick="shareToFacebook(event)"></a></div>
    </div>
    <div class="m-box">
        <p>分享到Twitter:</p>
        <div class="icn"><a class="wb9" onclick="shareToTwitter(event)"></a></div>
    </div>


    <script>
        var _title, _source, _sourceUrl, _pic, _showcount, _desc="desc", _summary="summary", _site,
                _width = 600,
                _height = 600,
                _top = (screen.height - _height) / 2,
                _left = (screen.width - _width) / 2,
                _url = 'http://www.baidu.com',
                _pic = '';
        //分享到新浪微博
        function shareToSinaWB(event) {
            event.preventDefault();
            var _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136';     //真實的appkey,必選參數
            _shareUrl += '&url=' + encodeURIComponent(_url || document.location);     //參數url設置分享的內容鏈接|默認當前頁location,可選參數
            _shareUrl += '&title=' + encodeURIComponent(_title || document.title);    //參數title設置分享的標題|默認當前頁標題,可選參數
            _shareUrl += '&source=' + encodeURIComponent(_source || '');
            _shareUrl += '&sourceUrl=' + encodeURIComponent(_sourceUrl || '');
            _shareUrl += '&content=' + 'utf-8';   //參數content設置頁面編碼gb2312|utf-8,可選參數
            _shareUrl += '&pic=' + encodeURIComponent(_pic || '');  //參數pic設置圖片鏈接|默認為空,可選參數
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',top=' + _top + ',left=' + _left + ',toolbar=no,menubar=no,scrollbars=no, resizable=1,location=no,status=0');
        }
        //分享到QQ空間
        function shareToQzone(event) {
            event.preventDefault();
            var _shareUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?';
            _shareUrl += 'url=' + encodeURIComponent(_url || document.location);   //參數url設置分享的內容鏈接|默認當前頁location
            _shareUrl += '&showcount=' + _showcount || 0;      //參數showcount是否顯示分享總數,顯示:'1',不顯示:'0',默認不顯示
            _shareUrl += '&desc=' + encodeURIComponent(_desc || '分享的描述');    //參數desc設置分享的描述,可選參數
            _shareUrl += '&summary=' + encodeURIComponent(_summary || '分享摘要');    //參數summary設置分享摘要,可選參數
            _shareUrl += '&title=' + encodeURIComponent(_title || document.title);    //參數title設置分享標題,可選參數
            _shareUrl += '&site=' + encodeURIComponent(_site || '');   //參數site設置分享來源,可選參數
            _shareUrl += '&pics=' + encodeURIComponent(_pic || '');   //參數pics設置分享圖片的路徑,多張圖片以"|"隔開,可選參數
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',top=' + _top + ',left=' + _left + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到百度貼吧
        function shareToTieba(event) {
            event.preventDefault();
            var _shareUrl = 'http://tieba.baidu.com/f/commit/share/openShareApi?';
            _shareUrl += 'title=' + encodeURIComponent(_title || document.title);  //分享的標題
            _shareUrl += '&url=' + encodeURIComponent(_url || document.location);  //分享的鏈接
            _shareUrl += '&pic=' + encodeURIComponent(_pic || '');    //分享的圖片
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到豆瓣
        function shareToDouban(event) {
            event.preventDefault();
            var _shareUrl = 'http://shuo.douban.com/!service/share?';
            _shareUrl += 'href=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&name=' + encodeURIComponent(_title || document.title);    //分享的標題
            _shareUrl += '&image=' + encodeURIComponent(_pic || '');    //分享的圖片
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到騰訊微博
        function shareToQQwb(event) {
            event.preventDefault();
            var _shareUrl = 'http://v.t.qq.com/share/share.php?';
            _shareUrl += 'title=' + encodeURIComponent(_title || document.title);    //分享的標題
            _shareUrl += '&url=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&appkey=5bd32d6f1dff4725ba40338b233ff155';    //在騰迅微博平台創建應用獲取微博AppKey
            _shareUrl += '&site=' + encodeURIComponent(_site || '');   //分享來源
            _shareUrl += '&pic=' + encodeURIComponent(_pic || '');    //分享的圖片,如果是多張圖片,則定義var _pic='圖片url1|圖片url2|圖片url3....'
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到人人網
        function shareToRenren(event) {
            event.preventDefault();
            var _shareUrl = 'http://share.rr.com/share/buttonshare.do?';     //這里的rr是renren,博客園好像和renren有仇
            _shareUrl += 'link=' + encodeURIComponent(_url || location.href);   //分享的鏈接
            _shareUrl += '&title=' + encodeURIComponent(_title || document.title);     //分享的標題
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到開心網
        function shareToKaixin(event) {
            event.preventDefault();
            var _shareUrl = 'http://www.kaixin001.com/rest/records.php?';
            _shareUrl += 'url=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&content=' + encodeURIComponent('分享的文字');    //需要分享的文字,當文字為空時,自動抓取分享網址的title
            _shareUrl += '&pic=' + encodeURIComponent(_pic || '');     //分享的圖片,多個使用半角逗號分隔
            _shareUrl += '&showcount=0';    //是否顯示分享數,顯示:'1',不顯示:'0'
            _shareUrl += '&style=11';      //顯示的樣式,必選參數
            _shareUrl += '&aid=' + encodeURIComponent(_site || '');    //顯示分享來源
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        function shareToKaixin2(event) {
            event.preventDefault();
            var _shareUrl = 'http://www.kaixin001.com/repaste/share.php?';
            _shareUrl += 'rtitle=' + encodeURIComponent(_title || document.title);   //分享的標題
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到facebook
        function shareToFacebook(event) {
            event.preventDefault();
            var _shareUrl = 'http://www.facebook.com/sharer/sharer.php?';
            _shareUrl += 'u=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&t=' + encodeURIComponent(_title || document.title);    //分享的標題
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到facebook
        function shareToFacebook(event) {
            event.preventDefault();
            var _shareUrl = 'http://www.facebook.com/sharer/sharer.php?';
            _shareUrl += 'u=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&t=' + encodeURIComponent(_title || document.title);    //分享的標題
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
        //分享到Twitter
        function shareToTwitter(event) {
            event.preventDefault();
            var _shareUrl = 'http://twitter.com/intent/tweet?';
            _shareUrl += 'url=' + encodeURIComponent(_url || location.href);    //分享的鏈接
            _shareUrl += '&text=' + encodeURIComponent(_title || document.title);    //分享的標題
            window.open(_shareUrl, '_blank', 'width=' + _width + ',height=' + _height + ',left=' + _left + ',top=' + _top + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
        }
    </script>

</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM