网页分享到微信、微博、QQ空间、百度贴吧等

WangXinPeng 2021-10-07 原文


网页分享到微信、微博、QQ空间、百度贴吧等

1.首先说明的是,pc端微信分享只能通过二维码来分享。

2.下面是js代码。

 //分享到新浪微博
    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 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\');
    }

  

发表于
2019-09-11 09:08 
菜鸟的编程VLOG 
阅读(422
评论(0
编辑 
收藏 
举报

 

版权声明:本文为WangXinPeng原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/WangXinPeng/p/11504326.html

网页分享到微信、微博、QQ空间、百度贴吧等的更多相关文章

  1. iOS 类似微博或朋友圈的信息流

    1.先上图:   image.png     image.png 因为做过了好几次这样的需求,所以这次想到把它 […]...

  2. 如何从零开始对接第三方登录(Java版):QQ登录和微博登录

    前言 个人网站最近增加了评论功能,为了方便用户不用注册就可以评论,对接了QQ和微博这2大常用软件的一键登录,总 […]...

  3. 呵呵气象台

    “ 每天叫醒你的除了梦想,还有呵呵气象台。”          2017-2-22 22:12,承载着对外经贸 […]...

  4. C#使用Selenium实现QQ空间数据抓取 登录QQ空间

    新建单元测试解决方案 安装Nuget包 我这里使用谷歌浏览器采集数据,所以就使用谷歌浏览器的驱动了,如果不喜欢 […]...

  5. 赵丽颖结婚了,分析下网友评论

      流量真的惹不起!我爬了1700条评论数据,包括了评论者评论内容、性别、微博认证与否、所属地区等指标,结果只 […]...

  6. QQ空间|qq人气号怎么赚钱?

    回报,付出的终极诉求,咱不论情怀。 在《怎么做一个QQ人气号》中,笔者大致提及,打造人气空间的流程,这里简单剖 […]...

  7. 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深?

    目录 一键生成属于自己的QQ历史报告,看看你对自己的QQ了解程度有多深? 简介 功能截图 如何运行 编写思路 […]...

随机推荐

  1. 从windows到linux,图形化操作到命令行操作讲解

    作为一个后端开发人员,刚开始进入到职场中,linux还不是必备项。但是随着开发经验的提升,慢慢就会接触到lin […]...

  2. Visual Studio 2017离线安装包,百度云分流

    Visual Studio正式版发布了,然而只能在线安装。虽然官方有提供了离线的方法,但还是蛮复杂的,所以我打 […]...

  3. 福利贴,vue-admin后台管理系统,全文注释

    # vue-admin-stepbystep > A Vue.js project### 项目背景这是公 […]...

  4. python函数eval与ast.literal_eval的区别

    一分钟学个小知识 eval与ast.literal_eval都可以将字符串还原成它能够转化成的数据类型,例如 […]...

  5. 网关的理解

    网关的理解   大家都知道,从一个房间走到另一个房间,必然要经过一扇门。同样,从一个网络向另一个网络发送信息, […]...

  6. kubernetes对象之Ingress

    系列目录 概述 向外网暴露集群内服务,以使客户端能够访问,有以下几种方法,本文重点描述Ingress。 Loa […]...

  7. 【转载】Android 关于arm64-v8a、armeabi-v7a、armeabi、x86下的so文件兼容问题

    转自:【欧阳鹏】http://blog.csdn.net/ouyang_peng Android 设备的CPU […]...

  8. nginx总结

    一:nginx可以实现反向代理,也可以实现动静分离、负载均衡: 1:具体配置如下所示: upstream :配 […]...

展开目录

目录导航