admin 管理员组文章数量: 887629
PC端实现浏览器点击分享到QQ好友,空间,微信,微博等
网上现在比较流行的是JIaThis,但是测试的时候,不能分享给QQ好友,一直卡在输入验证码,以下代码亲测有效,可直接使用
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri=""%> <%@taglib uri="" prefix="fn"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ".dtd"> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; response.setHeader("Cache-Control", "no-store"); response.setHeader("Pragrma", "no-cache"); response.setDateHeader("Expires", 0); %> <html> <head> <base href="<%=basePath%>"> <link rel="stylesheet" href="front/css/common.css" /> <link rel="stylesheet" href="front/css/header.css" /> <link rel="stylesheet" href="front/css/dr-info.css" /> <script src="front/js/jquery.min.js"></script> <script src="front/js/lunbo.js"></script> <script src="static/js/main.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <!-- 分享网页JS --> <script type="text/javascript" src=".js?uid=1" charset="utf-8"></script> <!-- JiaThis Button BEGIN --><div id="ckepop"> <span class="jiathis_txt">分享到:</span> <a rel="nofollow" onclick="jiathis_sendto('weixin');return false;" class="c1a"><span class="jtico jtico_weixin"> 微信<span class="media_go"></span></span></a> <a rel="nofollow" onclick="qqShare()" class="c1a"><span class="jtico jtico_cqq"> QQ好友<span class="media_go"></span></span></a> <a rel="nofollow" onclick="jiathis_sendto('tsina');return false;" class="c1a"><span class="jtico jtico_tsina"> 新浪微博<span class="media_go"></span></span></a> <a rel="nofollow" onclick="share(4)" class="c1a"><span class="jtico jtico_qzone"> QQ空间<span class="media_go"></span></span></a></div> <!-- JiaThis Button END --><script> function share(type) { ShareAll(type); } //获取页面描述(description) var meta = window.document.getElementsByTagName('meta'); var share_desc = ''; for (i in meta) { if (typeof meta[i].name != "undefined" && meta[i].name.toLowerCase() == "description") { share_desc = meta[i].content; } }//获取页面图片,可以多张,也可以一张,看自己的需求 var shareDara = { pic : (function() { var pics = '' var num = 0; $("#topicContent > p img").each(function(i, k) { if (i < 1) { pics += $(k).attr('src'); if (pics != '') return pics; } else { if (pics != '') return pics; pics += ',' + $(k).attr('src'); } }) return pics })(), title : (function() { return delHtmlTag($("#tTitle").html().trim()); })(), url : location.href, desc : (function() { return delHtmlTag($("#topicContent > p").eq(0).html() == undefined ? "" : $("#topicContent > p").eq(0).html().trim()); })() }//去掉所有的html标记 function delHtmlTag(str) { return str.replace(/<[^>]+>/g, "").trim(); }function ShareAll(type) { var obj_QZone = { url : "www.cnblogs.com/zhangpengnike/p/7543721.html", /* shareDara.url, *//*获取URL,可加上来自分享到QQ标识,方便统计*/ desc : '分享QQ空间测试1', /*分享理由(风格应模拟用户对话),支持多分享语随机展现(使用|分隔)*/ sharesource : 'qzone' };var obj_WeChat = { url : "www.cnblogs.com/zhangpengnike/p/7543721.html",/* shareDara.url, *//*分享URL*/ title : "用手机扫下面的二维码分享"//shareDara.title /*分享标题*/ };var s = [];if (type == 1) { //朋友圈 for ( var i in obj_WeChat) { s.push(i + '=' + encodeURIComponent(obj_WeChat[i] || '')); } var wechathref = "?" + s.join('&'); alert(wechathref); winpop(wechathref, 500, 450); } else if (type == 2) { //微信好友 for ( var i in obj_WeChat) { s.push(i + '=' + encodeURIComponent(obj_WeChat[i] || '')); } var wechathref = "?" + s.join('&'); winpop(wechathref, 500, 450); } else if (type == 4) { //QQ空间 for ( var i in obj_QZone) { s.push(i + '=' + encodeURIComponent(obj_QZone[i] || '')); } var qzonehref = "?" + s.join('&'); winpop(qzonehref, 800, 600); } } function winpop(url, iWidth, iHeight) { var openUrl = url; var iTop = (window.screen.availHeight - 50 - iHeight) / 2; var iLeft = (window.screen.availWidth - 30 - iWidth) / 2; window.open(openUrl,"_blank","toolbar=yes, location=yes, directories=no, status=no, menubar=yes, scrollbars=yes, resizable=no, copyhistory=yes, width="+ iWidth+ ", height="+ iHeight+ ", top="+ iTop + ",left=" + iLeft); } /* QQ好友分享功能 */ function qqShare(){ var p = { url:'www.cnblogs.com/zhangpengnike/p/7543721.html', /*获取URL,可加上来自分享到QQ标识,方便统计*/ desc:'发送信息给好友', summary:'', /*分享摘要(可选)*/ pics:'', /*分享图片(可选)*/ flash: '', /*视频地址(可选)*/ site:'', /*分享来源(可选) 如:QQ分享*/ style:'203', width:16, height:16 }; var s = []; for(var i in p){ s.push(i + '=' + encodeURIComponent(p[i]||'')); } var qhref = ".html?"+s.join('&'); $(".c1a").attr({href:qhref,target:"_blank"}); }; </script></body> </html>
转载于:.html
本文标签: PC端实现浏览器点击分享到QQ好友 空间 微信 微博等
版权声明:本文标题:PC端实现浏览器点击分享到QQ好友,空间,微信,微博等 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/jishu/1687916877h157168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论