网页分享到微信、微博、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‘);
    }

  

原文地址:https://www.cnblogs.com/WangXinPeng/p/11504326.html

时间: 2024-08-24 13:37:22

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

分享 朋友圈 微博 QQ空间

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>分享</title> </head> <body> <div class="share_top_style"> <a href="javascript:void()" clas

将网页分享到微信 微博 脸书 推特等社交媒体

tools.share = function(name) {     var list =     {         //微信         'wechat'   : function(selector){                         $(selector).append('<img src="http://qr.liantu.com/api.php?text='+encodeURIComponent(window.location.href)+'" /&

分享到微信微博空间等第三方平台的JS代码

分享功能有利于传播更多优质的内容,所以在web项目中也是比较常用的.今天就抽空整理下常用的分享平台的JS代码.这些代码可以在对应平台的官方网站上生成,官网上对分享内容的参数也有详尽说明.这里只对常用的几个参数说明下,案例未做兼容性处理,建议在chrome下预览. 1.分享到微信,易信 分享到微信,易信比较简单,贴上分享链接的二维码就可以了. 二维码生成地址:http://cli.im/ (网上随便搜的) 2.分享到新浪微博 代码如下: var _shareUrl = 'http://v.t.si

App分享之微信微博等各个社交平台的分享授权规则和常见问题

一.新浪微博分享规则 新浪微博支持分享类型: 应用内分享也就是网页分享支持: 文字,文字+图片,要分享链接需要链接添加在text里分享 客户端分享支持:文字,图片,文字+图片,图片+文字+链接 参数说明:text:不能超过140个汉字image:图片最大不超过5M,仅支持JPEG.GIF.PNG格式latitude:有效范围:-90.0到+90.0,+表示北纬longitude:有效范围:-180.0到+180.0,+表示东经 二.QQ好友分享规则 QQ好友分享支持:文字,图片,文字+图片+链接

网页分享到微信、微博、QQ等

首先要说明的是,pc端微信分享只能通过二维码来分享. 部分代码如下: //分享到新浪微博 function shareToSinaWB(event){ event.preventDefault(); var _shareUrl = 'http://v.t.sina.com.cn/share/share.php?&appkey=895033136'; //真实的appkey,必选参数 _shareUrl += '&url='+ encodeURIComponent(_url||documen

自己动手写js分享插件 支持https QQ空间,微信,新浪微博

废话不多说,传送门:http://download.csdn.net/detail/cometwo/9620943 支持https:https://www.aishandian.com/news-631.html 参考文章:http://www.cnblogs.com/hooray/archive/2011/09/10/2172946.html 动画效果 $(document).on("click", ".msb_main", function() { if($(t

轻松实现将网页“分享到”多个网站空间的悬浮按钮框

最近总看到一些朋友的空间.博客或某些网站上挂着一个悬浮框工具条,里面有一系列按钮,用于将当前网址分享到QQ空间.飞信空间.腾讯微博.新浪微博.开心网等社区.而这个悬浮框是由一个第三方网站提供的插件,悬浮框上有一个醒目的第三方网站标志,就像一个广告牌.这些挂着这个悬浮框的网站,无疑是在免费给这个第三方网站做广告,而且在做免费外链和免费流量.做网站的朋友肯定知道,这是一种很大的资源浪费(这种资源都可以换钱的). 而且它需要下载好几个较大的js文件,对性能会有所影响,让用户产生网站慢的不好印象. 其实

在网页中添加分享到微信、QQ、微博

参考地址:http://www.bshare.cn/help/installAction 在上面的地址中: 1.可选择分享到的位置,如QQ.微信.微博等 2.按钮的样式.悬浮或者以横幅的方式自己找位置放

andriod 实现新浪、QQ空间、微信朋友圈、微信好友分享功能

前言:自己在学习的过程中的一些操作过程,对分享的一些理解.下面就讲解一下: 下载地址:http://download.csdn.net/detail/u014608640/7490357 首先,我们需要去ShareSdk官方网站http://sharesdk.cn/ 去下载ShareSDK ,然后我们会有4个文件: 根据我自己在学习的过程中只用到了第一个文件夹的 libs目录的2个项目,这2个是必须要的,是ShareSdk提供的,然后需要将这2个放入到自己做的项目当中去,在Res目录下有一个 S