最新js分享到第三方平台代码

HTML代码

<ul class="sidebar-share">
  <li><a href="javascript:;" class="share-wechat" data-share="wechat" title="分享到微信"><i class="icu icu-share-wechat"></i></a></li>
  <li><a href="javascript:;" class="share-weibo" data-share="weibo" title="分享到新浪微博"><i class="icu icu-share-weibo"></i></a></li>
  <li><a href="javascript:;" class="share-qq" data-share="qq" title="分享给QQ好友"><i class="icu icu-share-qq"></i></a></li>
  <li><a href="javascript:;" class="share-qzone" data-share="qzone" title="分享到QQ空间"><i class="icu icu-qzone"></i></a></li>
  <li><a href="javascript:;" class="share-douban" data-share="douban" title="分享到豆瓣"><i class="icu icu-douban"></i></a></li>
  <li><a href="javascript:;" class="share-huaban" data-share="huaban" title="分享到花瓣"><i class="icu icu-huaban"></i></a></li>
  <li><a href="javascript:;" class="share-collect" data-share="collect" title="收藏当前页面"><i class="icu icu-collect"></i></a></li>
  <li><a href="javascript:;" class="share-print" data-share="print" title="打印当前页面"><i class="icu icu-print"></i></a></li>
</ul>


js代码

  $('.sidebar-share a').on('click', function() {
        let type = $(this).data('share');
        switch (type) {
            case 'wechat':
                layer.open({
                    type: 1,
                    title: false,
                    closeBtn: false,
                    scrollbar: false,
                    btnAlign: 'c',
                    btn: ['关闭'],
                    area: ['330px', '390px'],
                    content: '<div class="promote-open"><div class="title">微信扫一扫,转发朋友圈或好友</div><div class="promote-qrcode" style="margin-top: 25px"></div></div>',
                    success: function() {
                        $('.promote-qrcode').each(function() {
                            var defaultParams = {
                                text: share.url,
                                width: 252,
                                height: 252,
                                colorDark: '#000000',
                                colorLight: '#ffffff',
                                correctLevel: layui.qrcode.CorrectLevel.L
                            };
                            return new layui.qrcode(this, defaultParams);
                        });
                    }
                });
                return false;
            case 'weibo':
                var url = 'http://service.weibo.com/share/share.php?url=' + share.url + '&title=%23芦虎导航%23 %23好站推荐%23 ' + share.title + '&appkey=3001084155&pic=' + share.pic,
                    w = 650,
                    h = 490;
                break;
            case 'qq':
                var url = 'http://connect.qq.com/widget/shareqq/index.html?url=' + share.url + '&showcount=0&desc=&summary=' + share.desc + '&title=' + share.title + '&site=www.bldhw.com&pics=' + share.pic + '&style=203&width=19&height=22',
                    w = 750,
                    h = 650;
                break;
            case 'qzone':
                var url = 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?to=qzone&url=' + share.url + '&title=' + share.title + '&summary=' + share.desc,
                    w = 650,
                    h = 490;
                break;
            case 'douban':
                var url = 'https://www.douban.com/share/service?image=' + share.pic + '&href=' + share.url + '&name=' + share.title,
                    w = 750,
                    h = 610;
                break;
            case 'huaban':
                var url = 'https://huaban.com/bookmarklet/?url=' + share.url + '&title=' + share.title + '&media=' + share.pic,
                    w = 710,
                    h = 560;
                break;
            case 'collect':
                try {
                    window.external.addFavorite(share.url, share.title);
                } catch (e) {
                    try {
                        window.sidebar.addPanel(share.title, share.url, '');
                    } catch (e) {
                        layer.msg("请按 Ctrl+D 键添加到收藏夹", {
                            time: 2000
                        });
                    }
                }
                return false;
            case 'print':
                window.print();
                return false;
        }

        var openTop = (window.screen.height - 30 - h) / 2,
            openLeft = (window.screen.width - 10 - w) / 2;
        window.open(url, "newwindow", "height=" + h + ", width=" + w + ", top=" + openTop + ",left=" + openLeft + ", toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
    })


本文永久地址:http://www.huanghaiping.com/article/94.html
本文出自 黄海平博客 ,转载时请注明出处及相应链接。

发表我的评论
  

网友最新评论 (0)

暂无评论
返回顶部