欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js分享代码(新浪微博,腾讯微博,QQ空间,QQ好友)

程序员文章站 2022-06-26 13:25:45
...
<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8">
        <title>君乐科技js分享代码</title>
        <script src="js/jquery.js"></script>
    </head>

    <body style="background:#e5e6e6;">
        <section>
            <div>
                <div class="share-box">
                    <div>
                        <p>点击下方图标直接分享</p>
                        <ul>
                            <!-- 新浪微博 -->
                            <li>
                                <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,'','','http://www.junlenet.com/uploads/allimg/150510/1-150510104044.jpg','君乐科技','http://www.junlenet.com','页面编码gb2312|utf-8默认gb2312'));" class="invite-kinds2">新浪微博</a>
                            </li>
                            <!-- QQ好友 -->
                            <li>
                                <a href="javascript:;" id="qq_id" target="_blank">QQ好友</a>
                            </li>
                            <!-- QQ空间 -->
                            <li>
                                <a href="javascript:;" onclick="qqZone()">QQ空间</a>
                            </li>
                            <!-- 腾讯微博 -->
                            <li>
                                <a href="javascript:;" onclick="tencentWeiBo()">腾讯微博</a>
                            </li>
                        </ul>
                    </div>
                    <div class="ewm" id="qrcode"></div>
                    <!-- 参考:jquery.qrcode.js -->
                </div>
            </div>
        </section>
        <hr>
        <h3>直接使用百度分享</h3>
        <div class="bdsharebuttonbox">
            <a href="#" class="bds_more" data-cmd="more"></a>
            <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
            <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
            <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a>
        </div>
        <script>
            window._bd_share_config = {
                "common": {
                    //"bdSnsKey": {},
                    //"bdUrl":"",//分享的Url地址
                    "bdText": "分享的内容", //分享的内容
                    "bdDesc": "分享的摘要", //分享的摘要
                    "bdMini": 2, //下拉浮层中分享按钮的列数
                    "bdMiniList": ['qzone', 'tsina'], //    自定义下拉浮层中的分享按钮类型和排列顺序。
                    "bdPic": "", //分享的图片
                    "bdStyle": 1, //样式
                    "bdSize": 32 //    分享按钮的尺寸:16|24|32
                },
                "share": {},
                "slide": [{//浮窗分享设置
                    bdImg: 0,
                    bdPos: "right",
                    bdTop: 100
                }],
                "image": {//图片分享设置的值为数组或对象,值为数组时可对图片应用不同的设置。
                    "viewList": ["weixin", "tsina", "qzone", "tqq"],//自定义展示层中的分享按钮类型和排列顺序。
                    "viewText": "分享到:",
                    "viewSize": 16//图片分享展示层的图标大小。
                },
                "selectShare": {//划词分享设置
                    "bdContainerClass": null,
                    "bdSelectMiniList": ["weixin", "tsina", "qzone", "tqq"]
                }
            };
            with(document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
        </script>
        <script>
            var url = "http://www.junlenet.com";
            var desc_ = "君乐科技";

            function tencentWeiBo() {
                var _url = "http://www.junlenet.com";
                var _showcount = 0;
                var _summary = "";
                var _title = desc_;
                var _site = "http://www.junlenet.com";
                var _width = "600px";
                var _height = "800px";
                var _pic = "http://www.junlenet.com/uploads/allimg/150510/1-150510104044.jpg";
                var _shareUrl = 'http://share.v.t.qq.com/index.php?c=share&a=index';
                _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, 'width=' + _width + ',height=' + _height + ',left=' + (screen.width - _width) / 2 + ',top=' + (screen.height - _height) / 2 + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
            }
            var top = window.screen.height / 2 - 250;
            var left = window.screen.width / 2 - 300;
            var height = window.screen.height;
            var width = window.screen.width;
            /*title是标题,rLink链接,summary内容,site分享来源,pic分享图片路径,分享到新浪微博*/
            function shareTSina() {
                var title = desc_;
                var rLink = "http://www.junlenet.com";
                var backUrl = "http://wx.hengfu100.com/member/c_friend";
                var site = desc_;
                var pic = "http://www.junlenet.com/uploads/allimg/150510/1-150510104044.jpg";
                window.open("http://service.weibo.com/share/share.php?pic=" + encodeURIComponent(pic) + "&title=" +
                    encodeURIComponent(title.replace(/ /g, " ").replace(/<br \/>/g, " ")) + "&url=" + encodeURIComponent(rLink),
                    "分享至新浪微博",
                    "height=500,width=600,top=" + top + ",left=" + left + ",toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no");
            }

            function qqFriend() {
                var p = {
                    url: 'http://www.junlenet.com',
                    /*获取URL,可加上来自分享到QQ标识,方便统计*/
                    desc: '',
                    //title : '新玩法,再不来你就out了!', /*分享标题(可选)*/  
                    title: desc_,
                    summary: '',
                    /*分享摘要(可选)*/
                    pics: 'http://www.junlenet.com/uploads/allimg/150510/1-150510104044.jpg',
                    /*分享图片(可选)*/
                    flash: '',
                    /*视频地址(可选)*/
                    site: 'http://www.junlenet.com',
                    /*分享来源(可选) 如:QQ分享*/
                    style: '201',
                    width: 32,
                    height: 32
                };
                var s = [];
                for(var i in p) {
                    s.push(i + '=' + encodeURIComponent(p[i] || ''));
                }
                var url = "http://connect.qq.com/widget/shareqq/index.html?" + s.join('&');
                return url;
                //window.location.href = url;  
                //document.write(['<a class="qcShareQQDiv" href="http://connect.qq.com/widget/shareqq/index.html?',s.join('&'), '" >分享给QQ好友</a>' ].join(''));  
            }

            function qqZone() {
                var _url = "http://www.junlenet.com";
                var _showcount = 0;
                var _desc = desc_;
                var _summary = "";
                var _title = "君乐科技";
                var _site = "";
                var _width = "600px";
                var _height = "800px";
                var _summary = "";
                var _pic = "http://www.junlenet.com/uploads/allimg/150510/1-150510104044.jpg";
                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, 'width=' + _width + ',height=' + _height + ',top=' + (screen.height - _height) / 2 + ',left=' + (screen.width - _width) / 2 + ',toolbar=no,menubar=no,scrollbars=no,resizable=1,location=no,status=0');
            }

            $(function() {
                var url = qqFriend();
                $("#qq_id").attr("href", url);
            })
        </script>
    </body>

</html>