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

新浪微博,qq,QQ空间进行分享

程序员文章站 2022-06-26 13:28:43
...

开始引入bootstrap的css

<link rel="stylesheet" href="../css/bootstrap.min.css" />

html部分

<div class="fenxiang1">
		<p class="col-sm-5 col-xs-5 btn btn-success img-fen">
            <a href="#" class="a-link " onclick="open_share('qq')">
                
                QQ好友
            </a>
        </p>
 
                     <p class="col-sm-5 col-xs-5  btn btn-success img-fen">
            <a href="#" class="a-link" data-toggle="modal" data-target="#myWeixin">
                
                微信
            </a>
        </p>
        <p class="col-sm-5 col-xs-5  btn btn-success img-fen">
            <a href="#" class="a-link" onclick="open_share('qzone')">
                
                QQ空间
            </a>
        </p>
        <p class="col-sm-5 col-xs-5  btn btn-success img-fen">
            <a href="#" class="a-link" onclick="open_share('weibo')">
                
                新浪微博
            </a>
        </p><!-- /.modal-content -->
    	 <!-- 模态框(Modal) -->
             <p class="modal fade" id="myWeixin" tabindex="-1" role="dialog"
                  aria-labelledby="myModalLabel" aria-hidden="true">
                 <p class="modal-dialog" id="xian">
                     <p class="modal-content">
                         <p class="modal-header">
                             
                             <h4 class="modal-title" id="myModalLabel">
                                 用微信扫描二维码分享到朋友圈
                             </h4>
                         </p>
                         <p class="modal-body erweima">
                             <img src="http://s.jiathis.com/qrcode.php?url=<a rel='nofollow' href='http://www.baidu.com' target='_blank'>http://www.baidu.com</a>" alt="微信二维码" />
                         </p>
                         <p class="modal-footer">
                             <button type="button" class="btn btn-default"
                                     data-dismiss="modal">
                                 关闭
                             </button>
                         </p>
                     </p><!-- /.modal-content -->
                 </p><!-- /.modal-dialog -->
             </p><!-- /.modal -->
        </div>

js部分

function open_share(type) {
     	var shareUrl = '<a rel="nofollow" href="http://www.baidu.com" target="_blank">http:www.baidu.com</a>';
         var shareTitle = '自定义标题';
         var shareImg = 'http://s.jiathis.com/qrcode.php?url=' + shareUrl;
         var shareDesc = '自定义内容';
         var openUrl = '';
         switch (type) {
             case 'qzone':
                 openUrl = 'http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + shareUrl + '&title=' + shareTitle + '&pics=' + shareImg;
                 break;
             case 'weixin':
                 t_delay('请在微信客户端使用');
                 
                 return false;
                 break;
             case 'qq':
			 openUrl = 'http://connect.qq.com/widget/shareqq/index.html?url=' + shareUrl + '&desc=' + shareDesc + '&summary=' + shareDesc + '&site=' + shareUrl + '&pics=' + shareImg;
			      break;
			 case 'tqq':
			  openUrl = 'http://v.t.qq.com/share/share.php?title=' + shareTitle + '&url=' + shareUrl + '&site=' + shareUrl +'&pic=' + shareImg;
	              break;
	             case 'weibo':
	         
	          openUrl = 'http://service.weibo.com/share/share.php?title=' +  shareTitle + '&&source=' + shareUrl + '&sourceUrl=' + shareUrl + '&content=' + shareDesc + '&pic=' + shareImg;      
	              break;
	         }
	         window.open(openUrl);  
			}
			//判断微信
		    function is_weixn(){
		     var ua = navigator.userAgent.toLowerCase();
		     
		     if(ua.match(/MicroMessenger/i)=="micromessenger") {
		     	return true;
		     	alert();
		     	$("p").remove("p[class=modal-content]");
		         var $htmlLi = $('<img src="~/Content/WapHomeicon/xian.png" style="margin-left:120px;" alt="xian"/>');
		 
		         //创建DOM对象
		          var $ul = $("#xian");   //获取UL对象
		          $ul.append($htmlLi); //将$htmlLi追加到$ul元素的li列表
		
		         } else {
		             //不是微信
		             return false;
		
		            }
   
			}

微博和QQ,QQ空间都能够进行分享了,但那个微信,不知道怎么回事,没有测试出来,以后有谁用到这个代码,希望把微信的分享功能告诉我一下,到底能不能使用,我这个到底对不对。